public class MyCalculator { int a, b; Scanner sc = new Scanner(System.in);
int addition(){ System.out.println("Enter the two number for addition: "); a=sc.nextInt(); b=sc.nextInt(); return(a+b); } int subtraction(){ System.out.println("Enter the two number for subtraction: "); a=sc.nextInt(); b=sc.nextInt(); return(a-b); } int division(){ System.out.println("Enter the two number for division: "); a=sc.nextInt(); b=sc.nextInt(); return(a/b); } int multiplication(){ System.out.println("Enter the two number for division: "); a=sc.nextInt(); b=sc.nextInt(); return(a*b); } void normal(){ System.out.println("1: Addition"); System.out.println("2: Subtraction"); System.out.println("3: Division"); System.out.println("4: Multiplication"); System.out.println("Enter the action: "); int choice = sc.nextInt(); int Answer = 0; switch(choice){ case 1: Answer = addition(); break; case 2: Answer = subtraction(); break; case 3: Answer = division(); break; case 4: Answer = multiplication(); break; default: System.out.println("Invalid action!!"); } System.out.println("The answer is:"+ Answer); } int power(){ System.out.println("Enter 2 number for power: "); a= sc.nextInt(); b= sc.nextInt(); return ((int)Math.pow(a,b)); } int squareRoot(){ System.out.println("Enter the number for Square Root: "); a= sc.nextInt(); return((int)Math.sqrt(a)); } int log(){ System.out.println("Enter the number for Logarithmic value: "); a= sc.nextInt(); return((int)Math.log10(a)); } int naturalLog(){ System.out.println("Enter the number for Natural Log: "); a= sc.nextInt(); return((int)Math.log(a)); } int sin(){ System.out.println("Enter the degree for Sine value: "); a= sc.nextInt(); b= (int) Math.toDegrees(a); return((int)Math.sin(b)); } int decToBin(){ int dec_num, quot, i=1, j; int bin_num[] = new int[100]; System.out.print("Input a Decimal Number : "); dec_num = sc.nextInt();
System.out.print("Binary number is: "); for(j=i-1; j>0; j--) { System.out.print(bin_num[j]); } System.out.print("\n");
return 0; } int binToDec() { System.out.println("Enter a binary number:"); int n = sc.nextInt();
int decimal = 0, p = 0;
while (n != 0) { decimal += ((n % 10) * Math.pow(2, p)); n = n / 10; p++; }
System.out.println("The decimal for the given binary is:" +decimal); return 0; } int sip(){ System.out.print("Enter the principal: "); double principal = sc.nextDouble();
System.out.print("Enter the rate: "); double rate = sc.nextDouble();
System.out.print("Enter the time: "); double time = sc.nextDouble();
double interest = (principal * time * rate) / 100;