Guest User

Untitled

a guest
Oct 19th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. Scanner scan = new Scanner(System.in);
  2.  
  3. System.out.print("How many rows? ");
  4. Integer rows = Integer.valueOf(scan.nextLine());
  5.  
  6. System.out.print("How many columns?");
  7. Integer columns = Integer.valueOf(scan.nextLine());
  8.  
  9. double two_d[][] = new double[rows][columns];
  10.  
  11. int i, j;
  12.  
  13. for (i = 0; i < rows; i++) {
  14. System.out.print("Enter " + columns + " numbers seperated by comma (" + (i + 1) + " row): ");
  15. String[] line = scan.nextLine().split(",");
  16. for (j = 0; j < columns; j++) {
  17. two_d[i][j] = Double.parseDouble(line[j]);
  18. }
  19.  
  20. }
  21.  
  22. for (i = 0; i < rows; i++) {
  23. for (j = 0; j < columns; j++) {
  24. System.out.print(two_d[i][j] + " ");
  25. }
  26. System.out.println();
  27. }
  28.  
  29. scan.close();
  30. }
  31.  
  32. class Main {
  33. public static void main(String[] args) {
  34. Scanner scan = new Scanner(System.in);
  35.  
  36. System.out.print("How many rows? ");
  37. int rows = Integer.valueOf(scan.nextLine());
  38.  
  39. System.out.print("How many columns?");
  40. int columns = Integer.valueOf(scan.nextLine());
  41.  
  42. double two_d[][] = new double[rows][columns];
  43.  
  44. int i, j;
  45.  
  46. for (i = 0; i < rows; i++) {
  47. System.out.print("Enter " + columns + " numbers seperated by comma (" + (i + 1) + " row): ");
  48. String[] line = scan.nextLine().split(",");
  49. double low = Double.MIN_VALUE;
  50. for (j = 0; j < columns; j++) {
  51. two_d[i][j] = Double.parseDouble(line[j]);
  52. if (two_d[i][j] < low) {
  53. System.out.println("Error you number is to small"); //Set an error message
  54. i--;
  55. }
  56. else
  57. low = two_d[i][j];
  58. }
  59.  
  60. }
  61.  
  62. for (i = 0; i < rows; i++) {
  63. for (j = 0; j < columns; j++) {
  64. System.out.print(two_d[i][j] + " ");
  65. }
  66. System.out.println();
  67. }
  68.  
  69. scan.close();
  70. }
  71. }
Add Comment
Please, Sign In to add comment