Support Forums
My first program: A calculator - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Java Programming (https://www.supportforums.net/forumdisplay.php?fid=22)
+---- Thread: My first program: A calculator (/showthread.php?tid=3231)



My first program: A calculator - nevets04 - 11-29-2009

Code:
import java.util.Scanner;
public class calc
{
    public static void main(String[] args)
    {
        int x = 1;
        while (x == 1)
        {
            Scanner num = new Scanner(System.in);
            Scanner num2 = new Scanner(System.in);
            Scanner op = new Scanner(System.in);
            float userinput;
            float userinput2;
            int userinput3;
            System.out.print("Enter a Number: ");
            userinput = num.nextInt();
            System.out.print("Enter Another Number: ");
            userinput2 = num2.nextInt();
            System.out.println("1) Add");
            System.out.println("2) Subtract");
            System.out.println("3) Multiply");
            System.out.println("4) Divide");
            System.out.print("Enter an Operation: ");
            userinput3 = op.nextInt();
            if (userinput3 == 1)
            {         
                System.out.println(userinput + userinput2);
            }        
            else if (userinput3 == 2)
            {         
                System.out.println(userinput - userinput2);
            }
            else if (userinput3 == 3)
            {         
                System.out.println(userinput * userinput2);
            }
            else if (userinput3 == 4)
            {         
                System.out.println(userinput / userinput2);
            }
            else
            {
                System.out.println("Please enter a valid option...");
            }
        }
    }    
}