Advertisement
Guest User

Yeah...

a guest
Oct 25th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. /* public static void sizeMatters()
  2. {
  3. //Add Choice variables, array and choice scanner
  4. int choice;
  5. int[][] MySize;
  6. int findRow;
  7. int findColumn;
  8. int addData;
  9. Scanner newData = new Scanner(System.in);
  10. Scanner scan = new Scanner(System.in);
  11.  
  12. //Runs and reprints menu screen until User intentionally exits it (types 0)
  13. do
  14. {
  15. //Menu printout
  16. System.out.println("Welcome to the MySize array creator. Please pick an action\n");
  17. System.out.println("0: Exit Program");
  18. System.out.println("1: Enter Data into Cell");
  19. System.out.println("2: Print Array");
  20. System.out.println("3: Clear Array and Print");
  21.  
  22. choice = scan.nextInt();
  23.  
  24. //Switch statement for the different choices
  25. switch(choice)
  26. {
  27. case 0 :
  28. System.out.println("Exiting program...\n");
  29. break;
  30. case 1 :
  31. //Gets row, column, and number from user input; and prints out grid until number input is reached
  32. System.out.println("Please enter the row you wish to insert this value on");
  33. findRow = scan.nextInt();
  34. System.out.println("Please enter the column you wish to insert this value on");
  35. findColumn = scan.nextInt();
  36. System.out.println("Please enter the value you would like to add");
  37. addData = scan.nextInt();
  38. for(findRow = findRow; findRow < MySize.length; ++findRow)
  39. {
  40. for(findColumn = findColumn; findColumn < MySize[findRow].length; ++findColumn)
  41. {
  42. MySize[findRow][findColumn] = addData;
  43. }
  44. }
  45. break;
  46. case 2 :
  47. System.out.println("Printing Array...");
  48. //Prints out array in grid map based on data given from case 1
  49. for(int rowGrid = 0; rowGrid < MySize.length; ++rowGrid)
  50. {
  51. for(int colGrid = 0; colGrid <MySize[rowGrid].length; ++colGrid)
  52. {
  53. System.out.print(MySize[rowGrid][colGrid] + " ");
  54. }
  55. System.out.println();
  56. }
  57. break;
  58. case 3 :
  59. System.out.println("Clearing Array...");
  60. //Takes current Array size and fills all slots with zeros
  61. Arrays.fill(MySize, 0);
  62.  
  63. for(int clearArray = 0; clearArray < MySize.length; clearArray++)
  64. {
  65. System.out.print(MySize[clearArray] + " ");
  66. }
  67. break;
  68. default :
  69. System.out.println("Invalid Choice. Please enter one of the choices listed");
  70. break;
  71. }
  72. }
  73. while (choice != 0);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement