您好,登錄后才能下訂單哦!
轉(zhuǎn)載于 : http://www.verejava.com/?id=17159392878528
import java.util.Scanner;public class Test1 { /** * 模擬掃雷游戲, 在一個(gè)二維數(shù)組中, 1:無(wú)雷 2:有雷, 鍵盤輸入 行號(hào)和列號(hào), 判斷是否掃到了雷. */ 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); //鍵盤輸入 行號(hào)和列號(hào) System.out.println("請(qǐng)輸入行號(hào):"); int row = in.nextInt(); System.out.println("請(qǐng)輸入列號(hào):"); int col = in.nextInt(); int value = thundes[row][col];//從數(shù)組中獲得的值 //判斷是否掃到了雷 for (int i = 0; i < thundes.length; i++) { for (int j = 0; j < thundes[i].length; j++) { //判斷 value 是否在 數(shù)組中存在 并且 等于 2 if (value == thundes[i][j] && value == 2) { System.out.print("雷"); } else { System.out.print("* "); } } System.out.println(""); } } }
轉(zhuǎn)載于 : http://www.verejava.com/?id=17159392878528
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。