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

This is my code so far. It is able to prompt the user to give the specified number of inputs. I am trying to check to see if the inputs really are being stored to the storage array. The current location of the print statement does not work because the array is "unreachable".

pythonbeginner4556
  • 313
  • 1
  • 5
  • 14

1 Answers1

0

To print array in 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]);
}

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

Community
  • 1
  • 1
Ami Patel
  • 296
  • 1
  • 13