View Single Post
  #1 (permalink)  
Old 11-03-2007, 05:32 PM
notnumber6 notnumber6 is offline
Member
 
Join Date: Nov 2007
Posts: 7
notnumber6 is on a distinguished road
Adding Variables and using Switch
Hey guys, made a basic calculator, with the following code:

Code:
import java.lang.*; import java.util.*; import java.io.*; import java.net.*; public class CalcApp extends Object { public static void main(String[] argStrings) throws Exception { Scanner calcInput = new Scanner (System.in); System.out.printf ("Please enter your first number\n"); int firstInt = calcInput.nextInt(); System.out.printf ("Please enter your second number\n"); int secondInt = calcInput.nextInt(); System.out.printf ("Your second number is " + secondInt + "\n"); System.out.printf ("Your first number is " + firstInt + "\n"); System.out.printf ("Please enter your operator (1 = +) (2 = -) (3= /) \n"); int calcOperatorInput = calcInput.nextInt(); switch (calcOperatorInput) { case 1: System.out.println("Your Operator is (+)"); int calcAnswer = ( firstInt + secondInt ); break; case 2: System.out.println("Your Operator is (-)"); int calcAnswer = ( firstInt - secondInt ); break; case 3: System.out.println("Your Operator is (/)"); int calcAnswer = ( firstInt / secondInt ); break; default: System.out.println("Sorry, You must enter a number beetween 1-3"); break; } System.out.printf ("Your answer is"+ calcAnswer +"\n"); } }
Also we have the following error's

First of all calcAnswer is already defined, and also it cannot find symbol.

Thanks for the help
Reply With Quote
Sponsored Links