fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int total = 10;
  13. int[] myArray = new int [total];
  14.  
  15. Scanner input = new Scanner(System.in);
  16.  
  17. System.out.println("Enter numbers. To stop, enter 0.");
  18.  
  19. int numbers = input.nextInt();
  20. int i = 0;
  21. while (numbers != 0 && i < total) {
  22. myArray[i] = numbers;
  23. i++;
  24. numbers = input.nextInt();
  25. }
  26.  
  27. for (i = 0; i < myArray.length; i++)
  28. System.out.print(myArray[i] + ", ");
  29. }
  30. }
Success #stdin #stdout 0.06s 711680KB
stdin
1 2 3 4 5 6 7 8 9 10 0
stdout
Enter numbers.  To stop, enter 0.
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,