转载于 : http://www.verejava.com/?id=17159392878528
import java.util.Scanner;public class Test1 { /**
* 模拟扫雷游戏, 在一个二维数组中, 1:无雷 2:有雷, 键盘输入 行号和列号, 判断是否扫到了雷.
*/
public static void main(String[] args) { int[][] thundes = { { 1, 1, 1, 1 }, { 1, 1, 1, 1 }, { 1, 2, 1, 1 }, { 1, 1, 1, 1 } };
Scanner in = new Scanner(System.in); //键盘输入 行号和列号
System.out.println("请输入行号:"); int row = in.nextInt();
System.out.println("请输入列号:"); int col = in.nextInt(); int value = thundes[row][col];//从数组中获得的值
//判断是否扫到了雷
for (int i = 0; i < thundes.length; i++) { for (int j = 0; j < thundes[i].length; j++) { //判断 value 是否在 数组中存在 并且 等于 2
if (value == thundes[i][j] && value == 2) {
System.out.print("雷");
} else {
System.out.print("* ");
}
}
System.out.println("");
}
}
}
转载于 : http://www.verejava.com/?id=17159392878528
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:http://blog.itpub.net/10054744/viewspace-2212090/