Here,In Calculator all arithmetic function and Math Sqrt,Math pow,Math log functions.
CODING:import java.util.Scanner;
class main{
public static void main(String[] args){
calculate c=new calculate();
int i;
do{
System.out.print("1.SUM\n2.SUB\n3.MUL\n4.DIV\n5.POW\n6.SQRT\n7.LOG\n0.Exit\nEnterChoice:");
i=c.n.nextInt();
switch(i){
case 1:
c.set(1);
System.out.println("SUM : " + (c.a+c.b));
break;
case 2:
c.set(1);
System.out.println("SUB : " + (c.a-c.b));
break;
case 3:
c.set(1);
System.out.println("MUL : " + (c.a*c.b));
break;
case 4:
c.set(1);
System.out.println("DIV : " + (c.a/c.b));
break;
case 5:
c.set(1);
System.out.println("Power : " + Math.pow(c.a,c.b));
break;
case 6:
c.set(0);
System.out.println("SQRT : " + Math.sqrt(c.a));
break;
case 7:
c.set(0);
System.out.println("LOG : " + Math.log(c.a));
break;
case 0:break;
default:
System.out.println("Invalid Number!");
}}while(i!=0);
}
}
class calculate{
Scanner n=new Scanner(System.in);
int a,b;
void set(int i){
if(i==0){
System.out.print("Enter Number:");
a=n.nextInt();
}
else{
System.out.print("Enter Number:");
a=n.nextInt();
System.out.print("Enter Number:");
b=n.nextInt();
}
}
}
class main{
public static void main(String[] args){
calculate c=new calculate();
int i;
do{
System.out.print("1.SUM\n2.SUB\n3.MUL\n4.DIV\n5.POW\n6.SQRT\n7.LOG\n0.Exit\nEnterChoice:");
i=c.n.nextInt();
switch(i){
case 1:
c.set(1);
System.out.println("SUM : " + (c.a+c.b));
break;
case 2:
c.set(1);
System.out.println("SUB : " + (c.a-c.b));
break;
case 3:
c.set(1);
System.out.println("MUL : " + (c.a*c.b));
break;
case 4:
c.set(1);
System.out.println("DIV : " + (c.a/c.b));
break;
case 5:
c.set(1);
System.out.println("Power : " + Math.pow(c.a,c.b));
break;
case 6:
c.set(0);
System.out.println("SQRT : " + Math.sqrt(c.a));
break;
case 7:
c.set(0);
System.out.println("LOG : " + Math.log(c.a));
break;
case 0:break;
default:
System.out.println("Invalid Number!");
}}while(i!=0);
}
}
class calculate{
Scanner n=new Scanner(System.in);
int a,b;
void set(int i){
if(i==0){
System.out.print("Enter Number:");
a=n.nextInt();
}
else{
System.out.print("Enter Number:");
a=n.nextInt();
System.out.print("Enter Number:");
b=n.nextInt();
}
}
}
Comments
Post a Comment