View Single Post
  #3 (permalink)  
Old 11-03-2007, 05:42 PM
notnumber6 notnumber6 is offline
Member
 
Join Date: Nov 2007
Posts: 8
notnumber6 is on a distinguished road
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 calcAnswer = 1; 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"); } }
Have changed it,1 error down! But having a little problem, it says that calcAnswer variable has already been set, any ideas?
Reply With Quote