在字符串数组中存储用户输入?

时间:2015-10-02 15:55:45

标签: java arrays string

 Scanner input= new Scanner(System.in);
 int x=0;
 String [] storage=new String[3];
 while (x< 3){
   storage[x]= input.nextLine();
   x++;
 }

到目前为止,这是我的代码。它能够提示用户提供指定数量的输入。我试图检查输入是否真的存储到存储阵列。 print语句的当前位置不起作用,因为该数组是“无法访问”的。

1 个答案:

答案 0 :(得分:0)

在java中打印数组

String[] strArray = new String[] {"Reema", "Seema", "Neha"};

Arrays.asList(strArray).stream().forEach(s -> System.out.println(s));
for (int i = 0; i < intArray.length; i++) {
   System.out.print(intArray[i] + ", ");
}
   String line1 = scan.nextLine(); // Read 1st line
String[] numbers1 = line1.split(" "); // Split based on space
for(int i=0;i<numbers1.length;i++){
    array[i] = Integer.parseInt(numbers1[i]);
}

String line2 = scan.nextLine(); // Read 2nd line
String[] numbers2 = line2.split(" "); // Split based on space
for(int i=0;i<numbers2.length;i++){
    array2[i] = Integer.parseInt(numbers2[i]);
}

价:How to store input values in an array by using Scanner in Java