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
You are big programmer
ReplyDelete