I know that this isn't the most efficient way to make a calculator (asking for the operation first, requires more lines of code), but I feel like it is a better way to format the program's operation (the user is more comfortable with the way the program begins).
If you have any advice (such as making the code more efficient, while still asking for the operation beforehand), I'd love to hear it!!
Code
import java.util.Scanner;
public class Calculator {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
boolean loop = true;
while(loop == true)
{
System.out.println("What operation would you like to use?");
String operation = input.nextLine();
if (operation.equalsIgnoreCase("addition"))
{
double fnum, snum, answer;
System.out.println("Enter First Number:");
fnum = input.nextDouble();
System.out.println("Enter Second Number:");
snum = input.nextDouble();
System.out.println(fnum+snum);
}
else if (operation.equalsIgnoreCase("subtraction"))
{
double fnum, snum, answer;
System.out.println("Enter First Number:");
fnum = input.nextDouble();
System.out.println("Enter Second Number:");
snum = input.nextDouble();
System.out.println(fnum-snum);
}
else if (operation.equalsIgnoreCase("division"))
{
double fnum, snum, answer;
System.out.println("Enter First Number:");
fnum = input.nextDouble();
System.out.println("Enter Second Number:");
snum = input.nextDouble();
System.out.println(fnum/snum);
}
else if (operation.equalsIgnoreCase("multiplication"))
{
double fnum, snum, answer;
System.out.println("Enter First Number:");
fnum = input.nextDouble();
System.out.println("Enter Second Number:");
snum = input.nextDouble();
System.out.println(fnum*snum);
}
else if (operation.equalsIgnoreCase("exit"))
{
loop = false;
}
else
{
System.out.println("Incorrect Entry!");
}
}
}
}