Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* public static void sizeMatters()
- {
- //Add Choice variables, array and choice scanner
- int choice;
- int[][] MySize;
- int findRow;
- int findColumn;
- int addData;
- Scanner newData = new Scanner(System.in);
- Scanner scan = new Scanner(System.in);
- //Runs and reprints menu screen until User intentionally exits it (types 0)
- do
- {
- //Menu printout
- System.out.println("Welcome to the MySize array creator. Please pick an action\n");
- System.out.println("0: Exit Program");
- System.out.println("1: Enter Data into Cell");
- System.out.println("2: Print Array");
- System.out.println("3: Clear Array and Print");
- choice = scan.nextInt();
- //Switch statement for the different choices
- switch(choice)
- {
- case 0 :
- System.out.println("Exiting program...\n");
- break;
- case 1 :
- //Gets row, column, and number from user input; and prints out grid until number input is reached
- System.out.println("Please enter the row you wish to insert this value on");
- findRow = scan.nextInt();
- System.out.println("Please enter the column you wish to insert this value on");
- findColumn = scan.nextInt();
- System.out.println("Please enter the value you would like to add");
- addData = scan.nextInt();
- for(findRow = findRow; findRow < MySize.length; ++findRow)
- {
- for(findColumn = findColumn; findColumn < MySize[findRow].length; ++findColumn)
- {
- MySize[findRow][findColumn] = addData;
- }
- }
- break;
- case 2 :
- System.out.println("Printing Array...");
- //Prints out array in grid map based on data given from case 1
- for(int rowGrid = 0; rowGrid < MySize.length; ++rowGrid)
- {
- for(int colGrid = 0; colGrid <MySize[rowGrid].length; ++colGrid)
- {
- System.out.print(MySize[rowGrid][colGrid] + " ");
- }
- System.out.println();
- }
- break;
- case 3 :
- System.out.println("Clearing Array...");
- //Takes current Array size and fills all slots with zeros
- Arrays.fill(MySize, 0);
- for(int clearArray = 0; clearArray < MySize.length; clearArray++)
- {
- System.out.print(MySize[clearArray] + " ");
- }
- break;
- default :
- System.out.println("Invalid Choice. Please enter one of the choices listed");
- break;
- }
- }
- while (choice != 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement