A tree view of the P4 directory should look like this: P4/ ├── Chihiro.jpg ├── bin/ └── src/ └── Maze.java |
// Check program arguments if (args.length != 2) { System.out.println("usage: java P4 numberRows numberCols"); System.exit(-1); } // Store maze size int numberRows = Integer.parseInt(args[0]); int numberCols = Integer.parseInt(args[1]); // Print maze size System.err.println("Number of rows: " + numberRows); System.err.println("Number of columns: " + numberCols); // Initial position Scanner keyboard = new Scanner(System.in); System.out.print("Starting row: "); int currentRow = keyboard.nextInt(); System.out.print("Starting column: "); int currentCol = keyboard.nextInt(); keyboard.close(); // Create maze Maze maze = new Maze(numberRows, numberCols, currentRow, currentCol);
What does the following code print out after the prompt(s)? DO NOT RUN THIS CODE. Try and figure out what it does just by looking at it. You are not graded on correctness, this is purely to help you understand java. |
//imports import java.util.Scanner; //Interpreting Java public class R5 { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.print("Enter an integer between 0 and 10: "); int selection = keyboard.nextInt(); int number = 5; keyboard.nextLine(); // flush scanner switch (selection) { case 6: System.out.println("Case 6"); number = 1 + 2 * 3; break; case 2: System.out.println("Case 2"); number = 100; case 1: System.out.println("Case 1"); number = 5 * number; break; case 5: System.out.println("Case 5"); number = 5 / 2; break; case 4: System.out.println("Case 4"); number = 4; break; case 3: System.out.println("Case 3"); number = selection % 2; default: System.out.println("Default"); number = 1234; break; } System.out.println(number); System.out.print("Enter a salary: "); double salary = keyboard.nextDouble(); keyboard.nextLine(); // flush scanner if (0.0 <= salary && salary < 1000.0) { System.out.println("This salary is within the 0% tax bracket"); } else if (1000.0 <= salary && salary < 10000.0) { System.out.println("This salary is within the 15% tax bracket"); } else if ((10000.0 <= salary && salary < 50000.0) || (100000.0 <= salary && salary < 1000000.0)) { System.out.println("This salary is within the 20% tax bracket"); } else if (50000.0 <= salary && salary < 100000.0) { System.out.println("This salary is within the 18% tax bracket"); } else { System.out.println("This salary is within the flat rate tax bracket"); } int x = 2; if (x == 1) { System.out.println("x == 1"); } else if (x <= 2) { System.out.println("x <= 2"); } else if (x == 2) { System.out.println("x == 2"); } else if (x >= 2) { System.out.println("x >= 2"); } else { System.out.println("None of these"); } System.out.print("Enter an animal: "); String input = keyboard.nextLine(); System.out.println("The animal you entered was: " + input); System.out.println("The length of the animal name is: " + input.length()); System.out.println("The letter of the animal name at index 1 is: " + input.charAt(1)); System.out.print("Enter an integer: "); int inVal = keyboard.nextInt(); String s = "test"; System.out.println("The number you entered was: " + inVal); System.out.println(inVal + " * 5 = " + (inVal * 5)); System.out.println("You have " + inVal + " " + input + s.charAt(2)); keyboard.close(); } } // Example Console Input: -------------------------------- 3 956450.00 Peacock 6 --------------------------------Write your answer down (you should have 15 lines of output, including prompts) and your TA will go over it once everyone has finished.