0% found this document useful (0 votes)
13 views

Simple Calculator in Java

Calculator code in java

Uploaded by

Shubham Londhe
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)
13 views

Simple Calculator in Java

Calculator code in java

Uploaded by

Shubham Londhe
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/ 3

Simple Calculator in Java

import java.util.Scanner;

class SimpleCalculator {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Please type Arithmetic operation to be performed


(add,subtract,multiply,divide): ");

String operation = sc.nextLine();

System.out.println("Kindly enter first number: ");

int num1 = sc.nextInt();

System.out.println("Kindly enter second number: ");

int num2 = sc.nextInt();

int result;

switch(operation.toLowerCase()){

case "add": result = num1+num2;

System.out.println(num1+"+"+num2+"= "+result);

break;

case "subtract" : result = num1-num2;

System.out.println(num1+"-"+num2+"= "+result);

break;

case "multiply" : result = num1*num2;

System.out.println(num1+"*"+num2+"= "+result);

break;

case "divide" :

try {

result = num1/num2;
System.out.println(num1+"/"+num2+"= "+result);

}catch(ArithmeticException e){

System.out.println(num1+"/"+num2+"= Undefined");

break;

break;

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