Thursday, 22 October 2020

Calculator using Equals

Write a Java Program to make Calculator using Equals 
import java.util.Scanner;
public class CalciUsingEquals 
{
	public static void main(String[] args) 
	{
		int ans=0;
		Scanner s = new Scanner(System.in);
		System.out.println("Enter First Number...");
		int n1=s.nextInt();
		System.out.println("Enter Second Number...");
		int n2=s.nextInt();
		System.out.println("Enter Operator (+, -, *, /)...");
		String operation=s.next();
		System.out.println(n1+" "+ "*" +" "+n2+" = ");
			if(operation.equals("+"))
			{
				System.out.println(ans=n1+n2);
			}
			if(operation.equals("-"))
			{
				System.out.println(ans=n1-n2);
			}
			if(operation.equals("*"))
			{
				System.out.println(ans=n1*n2);
			}
			if(operation.equals("/"))
			{
				System.out.println(ans=n1/n2);
			}
	}
}


Output:
Enter First Number...
10
Enter Second Number...
5
Enter Operator (+, -, *, /)...
/
10 * 5 = 2


  1. Write a Java Program to make simple Calculator using methods
  2. Write a Java Program to make simple Calculator using if
  3. Write a Java Program to make a Menu Driven Calculator
  4. Write a Java Program to make simple Calculator using Equals
  5. Write a Java Program to make simple Calculator using switch...case


1 comment:

If you have any doubts, please let me know

Pattern 31 & 32