0% found this document useful (0 votes)
561 views1 page

Project 10 Calculator

This Java program uses a scanner to prompt the user to select an arithmetic operation and enter two operands. It then uses a switch statement to perform the selected operation and print the result, handling addition, subtraction, multiplication, division, or an invalid selection.

Uploaded by

api-236387090
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
561 views1 page

Project 10 Calculator

This Java program uses a scanner to prompt the user to select an arithmetic operation and enter two operands. It then uses a switch statement to perform the selected operation and print the result, handling addition, subtraction, multiplication, division, or an invalid selection.

Uploaded by

api-236387090
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Answers 10-5

ProjectCalculator
import java.util.*;
public class Calculator
{
public static void main(String args[])
{
System.out.println("Enter Add, Subtract, Multiply, or Divide below:\n");
System.out.println("
System.out.println("
System.out.println("
System.out.println("
System.out.print("

A. Addition");
S. Subtraction");
M. Multiplication");
D. Division\n");
Your choice? ");

Scanner kbReader = new Scanner(System.in);


String choice = kbReader.nextLine( );
System.out.print("\nEnter first operand. ");
double op1 = kbReader.nextDouble( );
System.out.print("\nEnter second operand.");
double op2 = kbReader.nextDouble( );
System.out.println(" ");
switch (choice)
{
case "Add":
System.out.println(op1 + " plus " + op2 + " = " + (op1 + op2) );
break;
case "Subtract":
System.out.println(op1 + " minus " + op2 + " = " + (op1 - op2) );
break;
case "Multiply":
System.out.println(op1 + " times " + op2 + " = " + (op1 * op2) );
break;
case "Divide":
System.out.println(op1 + " divided by " + op2 + " = " + (op1 / op2) );
break;
default:
System.out.println("Enter only Add, Subtract, Multiply or Divide!");
}
}
}

You might also like