-1
我想在輸入位置後立即獲取字符串,但它不起作用,我無法確定原因。 這是我的代碼。通過輸入地址找到二維數組中的值
import java.util.*;
public class LabTest1_Mardi {
public static void main (String [] args){
Scanner input = new Scanner (System.in);
String myArray [][] = { {"a","b"}, {"c","d"}, {"e","f"}, {"g","h"}};
//Getting row and cols
int rows = myArray.length;
int cols = myArray[0].length;
System.out.println("Rows = "+rows+" Cols = "+cols);
for (int x=0;x<rows;x++){
for (int y =0;y<cols;y++){
System.out.println("array "+x+" " + y + " : = "+myArray[x][y]);
}
}
System.out.println("Enter Possition row : ");
int posR = input.nextInt();
System.out.println("Enter Possition col : ");
int posC = input.nextInt();
System.out.println(myArray[posR+1][posC+1]);
input.close();
}
}
您是否記得使用'Scanner'類? (即'掃描儀輸入=新的掃描儀(System.in);' – PEF
我需要看到更多的代碼,以真正看到什麼是錯誤的有很多東西可能是基於這個錯誤 –
我提供了請檢查並通知我 –