+ 3

# Can someone please share me a code to create a calculator

7 Answers

+ 14

//[ A Simple Calculator for You ]
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Maths Maths = new Maths();
double answer = 0;
double inputA, inputB;
char operator;
boolean done = false;
while (done == false) {
System.out.print("Please enter your sum: ");
inputA = input.nextDouble();
operator = input.next().charAt(0);
inputB = input.nextDouble();
switch (operator) {
case '+': answer = Maths.add(inputA, inputB);
break;
case '-': answer = Maths.subtract(inputA, inputB);
break;
case '*': answer = Maths.multiply(inputA, inputB);
break;
case '/': answer = Maths.divide(inputA, inputB);
break;
case '^': answer = Maths.power(inputA, inputB);
break;
}
System.out.println(answer);
}
[The code isn't made by me, thanks to @Mayank who made this code!]

+ 10

wow.

+ 10

XD

+ 10

Next time you need a code, please search the uploaded codes on sololearn for it before you ask one! [Not necessarily, but this will save the time]

+ 7

I would but I've only made one in c++ and Python as I do not know java

+ 1

thanks to y'all that answered my Q

0

simplest code to create a calculator would be mad - calculator - algebra - etc... well something similar to this concept...