I need a Calcultor Java Program with main function.
Answers
Answered by
4
int a,b,result=0; char c;
System.out.println("Enter no. :"); a = input.nextInt(); System.out.println("Enter no. :"); b = input.nextInt(); System.out.println("Enter Operator :"); String st = input.next(); c = st.charAt(0);
Switch(c)
{
case '+' :
result = a+b;
System.out.println("Result = "+result);
break;
case '-' :
result = a-b;
System.out.println("Result = "+result);
break;
case '*' :
result = a*b;
System.out.println("Result = "+result);
break;
case '/' :
result = a/b;
System.out.println("Result = "+result);
break;
default :
System.out.println("Syntax error");
}
}
}
System.out.println("Enter no. :"); a = input.nextInt(); System.out.println("Enter no. :"); b = input.nextInt(); System.out.println("Enter Operator :"); String st = input.next(); c = st.charAt(0);
Switch(c)
{
case '+' :
result = a+b;
System.out.println("Result = "+result);
break;
case '-' :
result = a-b;
System.out.println("Result = "+result);
break;
case '*' :
result = a*b;
System.out.println("Result = "+result);
break;
case '/' :
result = a/b;
System.out.println("Result = "+result);
break;
default :
System.out.println("Syntax error");
}
}
}
Similar questions