Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login



Write a program with an exception handler that deals with nonnumeric operands;then write another program without using an exception handler to achieve the same objective. Your program should display a message that informs the user of the wrong operand type before exiting. I wrote this much of the program (attachment) but I cant get it to work with subtration and if a user inputs a wrong input for example 5x. Any clues? Attachments Tags Clarifications


JAVA Calculator Solution


JAVA source code is attached.

When running from command line or IDE, escape the operand as follows because JAVA treats the '*' operand as a special character and cannot be passed as an argument otherwise.

1 \\* 8
1 \\+ 8
1 \\- 8
1 \\/ 8
Attachments (1 K) Download Preview
!= 3) { System.out.println("Enter numeric output"); System.exit(0); } try { num1 = Integer.parseInt(args[0]); } catch (NumberFormatException ex) { System.out.println("Wrong Input: " + args[0]); return; } try { num2 = Integer.parseInt(args[2]); } catch (Exception ex) { (1 K) Download Preview
because escape character required switch (args[1].charAt(2)) { case '+': result = num1 + num2; break; case '-': result = num1 - num2; break; case '*': result = num1 * num2; break; case '/': result = num1 / (float)num2;

Purchase Answer