Basics_Que_16

Home / Java Practice Question / Basics_Que_16

Basics_Que_16


Write a Java program to create a simple calculator.

program : 



public class Loop {

public static int basicCalculator(int num1 , int num2){

Scanner sh = new Scanner(System.in);
char sign=sh.next().charAt(0);

if(sign=='+'){
return num1+num2;
} else if (sign=='-') {
return num1-num2;
}else if(sign=='*'){
return num1*num2;
}else if(sign=='/'){
return num1/num2;
}

return -1; // It is dummy return.....
}

}