How to make a calculator in Java
Answers
Answered by
1
Calculator in Java with Source Code: We can develop calculator in java with the help of AWT/Swing with event handling. Let's see the code of creating calculator in java.
Answered by
0
Answer:
import java.util.*;
public class Main
{
public static void main(String args[ ])
{
char X;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number = ");
int a=sc.nextInt( );
System.out.print("Enter character = ");
X=sc.next( ).charAt(0);
System.out.print("Enter a number = ");
int b=sc.nextInt( );
System.out.print("The answer is ");
if(X=='+')
{
System.out.println(a+b);
}
else if(X=='-')
{
System.out.println(a-b);
}
else if(X=='×')
{
System.out.println(a*b);
}
else if(X=='÷')
{
System.out.println(a/b);
}
}
}
Hope this will help you.
Similar questions