import java.util.Scanner;
/** 
 *  This class will demonstrate problems with bad input
 *
 *  @author Nancy Harris
 *  @version V1 - 09/26/07
 */
public class BadInput
{
	/**
	 * main prompts for two values and performs various operations on those operands
	 *
	 * @param args unused in this program
	 */ 
	public static void main(String args[])
	{
		int 		operand1, operand2;
		int 		result;
		String	badValue;
		Scanner  keyboard;
				
		// instantiate our Scanner object
		keyboard = new Scanner(System.in);
		
		System.out.print("Enter two integers separated by a space: ");
		
		// must protect against ugly input
		if(keyboard.hasNextInt())
		{
			operand1 = keyboard.nextInt();
		}
		else
		{
			operand1 = Integer.MAX_VALUE;
		}
		
		if(keyboard.hasNextInt())
		{
			operand2 = keyboard.nextInt();
		}
		else
		{
			operand2 = Integer.MAX_VALUE;
		}

		System.out.print("\n");
		
		// carry out operations
		result = operand1 + operand2;
		System.out.println(operand1 + " + " + operand2 + " = " + result);
		
		result = operand1 - operand2;
		System.out.println(operand1 + " - " + operand2 + " = " + result);
		
		result = operand1 * operand2;
		System.out.println(operand1 + " * " + operand2 + " = " + result);
		
		// must protect from 0 value still
			
		if (operand2 != 0)
		{
			result = operand1 / operand2;
			System.out.println(operand1 + " / " + operand2 + " = " + result);
		
			result = operand1 % operand2;
			System.out.println(operand1 + " % " + operand2 + " = " + result);
		}
		else
			System.out.println("Cannot divide by zero");
	}	
}
		