fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Lab08_Build_2dArray
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner console = new Scanner(System.in);
  10. System.out.print("Enter the number of rows: ");
  11. int nRows = console.nextInt();
  12. nRows = Math.max(0,nRows);
  13.  
  14. int ir,ic;
  15.  
  16. int[][] data = new int[nRows][];
  17.  
  18. for(ir=0;ir<nRows;ir++) {
  19. ic = 0;
  20. String s = console.nextLine();
  21. String[] rowElements = s.split(",");
  22. while(ic < rowElements.length) {
  23. data[ir][ic] = Integer.parseInt(rowElements[ic]);
  24. ic++;
  25. }
  26. }
  27.  
  28. console.close();
  29. }
  30. }
  31.  
Runtime error #stdin #stdout #stderr 0.11s 35412KB
stdin
3
7,2,8,0
3,2,4,1
5,4,2,1,7
stdout
Enter the number of rows: 
stderr
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
	at java.base/java.lang.Integer.parseInt(Integer.java:668)
	at java.base/java.lang.Integer.parseInt(Integer.java:776)
	at Lab08_Build_2dArray.main(Main.java:23)