New Question:-
WAP in JAVA to make a Calculator.
Note:-
• Besides Addition, Subtraction, Division and Multiplication, a Calculator should also include Binary Calculator ( Including conversion of Number System)
_
• Quality Answers...
• No spammimg/plagiarized answer
• All the best :)
Answers
> Required Question:-
WAP in JAVA to make a Calculator.
Note:-
• Besides Addition, Subtraction, Division and Multiplication, a Calculator should also include Binary Calculator ( Including conversion of Number System)
> Programming:-
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
.
System.out.print("Enter two numbers: (for conversion enter only one number)";
double first = reader.nextDouble();
double second = reader.nextDouble();
System.out.print("Enter an operator (+, -, *, /,BtoD,DtoB): ");
//BtoD for binary to decimal
//DtoB for decimal to binary
char operator = reader.next().charAt(0);
double result;
switch (operator) {
case '+':
result = first + second;
break;
case '-':
result = first - second;
break;
case '*':
result = first * second;
break;
case '/':
result = first / second;
break;
⠀⠀⠀case 'BtoD':
result = Integer.toBinaryString(first);
break;
⠀⠀⠀case 'DtoB':
result = Integer.parseInt(first);
break;
// operator doesn't match any case constant (+, -, *, /,BtoD,DtoB)
default:
System.out.printf("Error! operator is not correct");
return;
}
System.out.println(first + " " + operator + " " + second + " = " + result);
}
}
> Programmed in JAVA.
> you can also made this using java applet or netbean for graphic interface.
In this Program we are making a simple calculator that performs addition, subtraction, multiplication and division based on the user input. The program takes the value of both the numbers (entered by user) and then user is asked to enter the operation (+, -, * and /), based on the input program performs the selected operation on the entered numbers using switch case.
If you are new to java, refer this Java tutorial to start learning java programming from basics.
please mark me brainliest