-1
私は位置iの入力の直後に文字列を取得しようとしていますが、機能していません。 これは私のコードです。アドレスを入力して2D配列の値を見つける
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
実際に何が間違っているかを見るにはもっと多くのコードを見る必要がありますが、これに基づいて間違っている可能性のあることがたくさんあります。 –
コードをチェックして私に知らせてください –