溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Java 數(shù)組 之 二維數(shù)組 掃雷實(shí)例

發(fā)布時(shí)間:2020-08-04 17:12:28 來(lái)源:ITPUB博客 閱讀:202 作者:huyang_ya 欄目:編程語(yǔ)言

轉(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  

向AI問(wèn)一下細(xì)節(jié)

免責(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)容。

AI