This is a simple Java calculator I wrote. It's my first program in Java so let me know how i did. I'm aware I could have used functions, but I haven't learned that in java yet.
Code
import java.util.Scanner;
public class Calculator
{
public static void main(String args[])
throws java.io.IOException
{
char choice;
// The calculator menu
System.out.println("\t*Calculator*");
System.out.println("Menu:");
System.out.println("\t1. Addition");
System.out.println("\t2. Subtraction");
System.out.println("\t3. Multiplication");
System.out.println("\t4. Division");
System.out.println("\t5. Raise to Power");
System.out.println("\t0. Quit");
System.out.print("Choice: "); // prompts for choice
choice = (char) System.in.read(); // reads in choice
System.out.println(""); // blank line to seperate menu
Scanner sc;
double A, B, C;
switch (choice)
{
case '1':
// Description of addition
System.out.println("Adds two numbers:");
System.out.println("\tA + B = C");
// Inputs A and B
System.out.print("Enter A: ");
sc = new Scanner(System.in);
A = sc.nextDouble();
System.out.print("Enter B: ");
sc = new Scanner(System.in);
B = sc.nextDouble();
sc.close();
// Adds A and B to find C and shows the answer
C = A + B;
System.out.println(A + " + " + B + " = " + C);
break;
case '2':
// Description of subtraction
System.out.println("Subtracts one number from another");
System.out.println("\tA - B = C");
// Inputs A and B
System.out.print("Enter A: ");
sc = new Scanner(System.in);
A = sc.nextDouble();
System.out.print("Enter B: ");
sc = new Scanner(System.in);
B = sc.nextDouble();
sc.close();
// Subtracs B from A to find C and shows the answer
C = A - B;
System.out.println(A + " - " + B + " = " + C);
break;
case '3':
// Description of Multiplication
System.out.println("Multiplies two numbers");
System.out.println("\tA * B = C");
// Inputs A and B
System.out.print("Enter A: ");
sc = new Scanner(System.in);
A = sc.nextDouble();
System.out.print("Enter B: ");
sc = new Scanner(System.in);
B = sc.nextDouble();
sc.close();
// Multiplies A and B to make C and shows answer
C = A * B;
System.out.println(A + " * " + B + " = " + C);
break;
case '4':
// Description of Division
System.out.println("Divides one number by another");
System.out.println("\tA / B = C");
// Inputs A and B
System.out.print("Enter A: ");
sc = new Scanner(System.in);
A = sc.nextDouble();
System.out.print("Enter B: ");
sc = new Scanner(System.in);
B = sc.nextDouble();
sc.close();
// Divides A by B to make C and shows answer
C = A / B;
System.out.println(A + " / " + B + " = " + C);
break;
case '5':
// Description of Raise to a Power
System.out.println("Gives A to the B power");
System.out.println("\t A^B = C");
// Inputs A and B
System.out.print("Enter A: ");
sc = new Scanner(System.in);
A = sc.nextDouble();
System.out.print("Enter B: ");
sc = new Scanner(System.in);
B = sc.nextDouble();
sc.close();
C = Math.pow(A, B);
System.out.println(A + "^" + B + " = " + C);
break;
default:
System.out.println("Quitting...");
}
}
}


![[Image: ebisfS8.png]](https://i.imgur.com/ebisfS8.png)