Making a Calculator with the help of java programming.
Copy the code below for practice.
// nileshdeoree.blogspot.com
package google ;
import java.util.Scanner;
public class Calculator {
public static void main (String args[]){
Scanner input=new Scanner (System.in);
char Y,condition,operator;
float a,b,result;
System.out.println("Enter your first number");
a=input.nextFloat();
System.out.println("Enter your second number");
b=input.nextFloat();
System.out.println("Enter an operator");
operator = input.next().charAt(0);
switch(operator){
case '+':
result=a+b;
System.out.println(result);
break;
case '-':
result=a-b;
System.out.println(result);
break;
case '*':
result=a*b;
System.out.println(result);
break;
case '/':
result=a/b;
System.out.println(result);
break;
case '%':
result=a%b;
System.out.println(result);
break;
}
}
}
Comments
Post a Comment