Java 如何在另一个数组中存储几个数组的相同索引值
导入java.util.Scanner 公共类名称查找器{Java 如何在另一个数组中存储几个数组的相同索引值,java,arrays,Java,Arrays,导入java.util.Scanner 公共类名称查找器{ public static void main(String[] args) { System.out.println(" NAME PREDICTER "); System.out.println(" Row 1 A B C D E F"); System.out.println(" Row 2 G H I J K L"); System
public static void main(String[] args) {
System.out.println(" NAME PREDICTER ");
System.out.println(" Row 1 A B C D E F");
System.out.println(" Row 2 G H I J K L");
System.out.println(" Row 3 M N O P Q R");
System.out.println(" Row 4 S T U V W X");
System.out.println(" Row 5 Y Z . . . .");
System.out.println("enter the length of your first name in number!!! EX: vino , so length is 4");
Scanner scanner = new Scanner(System.in);
int y = scanner.nextInt();
int s[] = new int [20];
for(int i=1;i<=y;i++)
{
System.out.println("Enter whether the "+i+"letter of your name is in which row");
Scanner scanner1 = new Scanner(System.in);
s[i] = scanner1.nextInt();
}
char a[] = {'A','B','C','D','E','F'};
char b[] = {'G','H','I','J','K','L'};
char c[] = {'M','N','O','P','Q','R'};
char d[] = {'S','T','U','V','W','X'};
char e[] = {'Y','Z','.','.','.','.'};
for(int i=0;i<6;i++){
for(int j = 0; j <=y; j++) {
switch(s[j] ) { // Since counting starts from 0.
case 1: System.out.print("\t"+a[i]);break;
case 2: System.out.print("\t"+b[i]); break;
case 3: System.out.print("\t"+c[i]); break;
case 4: System.out.print("\t"+d[i]); break;
case 5: try {
System.out.print("\t"+e[i]);
} catch(ArrayIndexOutOfBoundsException ex) {
System.out.println("\t "); // Print an empty space with a \t character.
}
break; // Prone to ArrayIndexOutOfBoundsException
}
}
System.out.println(" "+"Row"+ (i+1)); // Print a newline character after printing every line
}
输出:
名称预测器
第1行A B C D E F
第2行G H I J K L
第3排无P Q R
第4排S T U V W X
第5行Y Z。
在数字中输入您的名字的长度!!!葡萄酒,所以长度是4
3.
输入您的姓名字母是否在哪一行
4.
输入您姓名的2个字母是否在哪一行
2.
输入您姓名的3个字母是否在哪一行
3.
S G M第1行
第2行
第3排
V J P第4排
W K Q第5行
X L R第6排
所需帮助:
现在我需要将第1行中的所有字母表存储到单独的数组中。
例如,第1行[]={S,G,M}和第2行[]={T,H,N}等等……。您要求的是2D数组的“转置”方法。据我所知,Java没有现成的方法,但是自己编写一个应该很容易。创建一个新的二维数组,并用其中的值填充它。您尝试了什么?你被困在哪里了?现在我把密码放好了