如何在另一个单个数组中存储少数数组的相同索引值

时间:2014-10-19 01:14:40

标签: java arrays

import java.util.Scanner;

public class namefinder {

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行M N O P Q R  第4行S T U V W X.  第5行Y Z. 。 。 。 输入您的名字的长度! EX:vino,长度为4 3 输入您姓名的1letter是否在哪一行 4 输入您姓名的2letter是否在哪一行 2 输入您姓名的3letter是否在哪一行 3     S G M Row1     T H N Row2     U I O Row3     V J P Row4     W K Q Row5

X L R Row6

需要帮助: 现在我需要存储第1行的所有字母表以分隔数组。 即row1 [] = {S,G,M}和row2 [] = {T,H,N}等等............

0 个答案:

没有答案