0% found this document useful (0 votes)
27 views7 pages

Package Import Public Class Public Static Void: //question

The document contains code for a simple Java calculator program that allows a user to choose between addition, subtraction, multiplication, or division. It prompts the user to select an operation, then takes in two numbers from the user and prints out the result. The program uses if/else statements to check the user's choice and call the appropriate calculation method.

Uploaded by

Jelo Artoza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views7 pages

Package Import Public Class Public Static Void: //question

The document contains code for a simple Java calculator program that allows a user to choose between addition, subtraction, multiplication, or division. It prompts the user to select an operation, then takes in two numbers from the user and prints out the result. The program uses if/else statements to check the user's choice and call the appropriate calculation method.

Uploaded by

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

package newpackage;

import java.util.Scanner;
public class Activity71 {
public static void main(String args[]) {

//Question
Scanner choice = new Scanner(System.in);
System.out.println(
"My Simple Calculator \n A) Addition \n B) Subtraction \n C) Multiplication \n D) Division
\nKindly enter the letter of your choice: (Case Sensitive)");
String letter = choice.nextLine();

//Letters
String a = "A";
String b = "B";
String c = "C";
String d = "D";

//If addition
if (letter.equals(a)) {
System.out.println("Your choice is addition");
//first number
Scanner first = new Scanner(System.in);
System.out.println("Enter your first number:");
double num1 = first.nextDouble();
//second number
Scanner second = new Scanner (System.in);
System.out.println("Enter second number:");
double num2 = second.nextDouble();
//result
double result = num1 + num2;
System.out.println("The sum is " + result);
}

//If subtraction
if (letter.equals(b)) {
System.out.println("Your choice is subtraction");
//first number
Scanner first = new Scanner(System.in);
System.out.println("Enter your first number:");
double num1 = first.nextDouble();
//second number
Scanner second = new Scanner (System.in);
System.out.println("Enter second number:");
double num2 = second.nextDouble();
//result
double result = num1 - num2;
System.out.println("The difference is " + result);
}

//If multiplication
if (letter.equals(c)) {
System.out.println("Your choice is multiplication");
//first number
Scanner first = new Scanner(System.in);
System.out.println("Enter your first number:");
double num1 = first.nextDouble();
//second number
Scanner second = new Scanner (System.in);
System.out.println("Enter second number:");
double num2 = second.nextDouble();
//result
double result = num1 * num2;
System.out.println("The product is " + result);
}

//If division
if (letter.equals(d)) {
System.out.println("Your choice is division");
//first number
Scanner first = new Scanner(System.in);
System.out.println("Enter your first number:");
double num1 = first.nextDouble();
//second number
Scanner second = new Scanner (System.in);
System.out.println("Enter second number:");
double num2 = second.nextDouble();
//result
double result = num1 / num2;
System.out.println("The quotient is " + result);
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy