import java.util.Scanner; /** * scope example.. * * @author William McDaniel Albritton */ public class ScopeExample2 { /** * main method starts the program.. * @param arguments are not used.. */ public static void main(String[] arguments) { //declare, instantiate, and initialize variables (objects) Scanner input = new Scanner(System.in); String number1 = new String("user input 1"); String number2 = new String("user input 1"); Integer x = new Integer(1); Integer y = new Integer(2); //get user input System.out.print("Enter two integers on two separate lines: "); number1 = input.nextLine(); number2 = input.nextLine(); try{ //convert to integer x = Integer.parseInt(number1); y = Integer.parseInt(number2); //multiple if-statements if(x > y){ Integer z = x / y; System.out.println("z = " + z); } else if(x < y){ Integer z = x % y; System.out.println("z = " + z); } else{ Integer z = x * y; System.out.println("z = " + z); } } catch(NumberFormatException exception){ System.out.println("ERROR: You should enter two integers with no extra spaces!"); } catch(ArithmeticException exception2){ System.out.println("ERROR: Don't divide by zero!"); } } }