import java.util.Scanner;

public class Calculator{

	static double result, num1, num2;

	public static double add(double a, double b){
		result = a + b;
		return result;
	}
	public static double subtract(double a, double b){
		result = a - b;
		return result;
	}
	public static double multiply(double a, double b){
		result = a * b;
		return result;
	}
	public static double divide(double a, double b){
		result = a / b;
		return result;
	}
	public static double sqrt(double a, double b){
		result = Math.sqrt(a);
		return result;
	}
	public static double power(double a, double b){
		result = Math.pow(a,b);
		return result;
	}
	public static double mod(double a, double b){
		result = a % b;
		return result;
	}
	public static double average(double a, double b){
		result = (a + b) / 2;
		return result;
	}
	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		System.out.println("What would you like to do? \n 1. Add \n 2. Subtract \n 3. Multiply \n 4. Divide \n 5. Square Root \n 6. Power \n 7. Modulus \n 8. Average");

		int operation = input.nextInt();

		while (operation < 1 || operation > 8) {
			System.out.println("Please try again:");
			operation = input.nextInt();
		}

		// If correct operation is entered
		if (operation >=1 && operation <= 8) {
			if (operation == 5) {
				System.out.println("Enter Value");
				num1 = input.nextDouble();
			} else {
				System.out.println("Enter Value 1:");
				num1 = input.nextDouble();
				System.out.println("Enter Value 2:");
				num2 = input.nextDouble();
				while (operation==4 && num2 == 0) {
					System.out.println("You can't divide by zero '0'. Enter Value 2 again:");
					num2 = input.nextDouble();
				}

			}
		
			switch (operation){
				case 1:
					add(num1, num2);
				break;
				case 2:
					subtract(num1, num2);
				break;
				case 3:
					multiply(num1, num2);
				break;
				case 4:
					divide(num1, num2);
				break;
				case 5:
					sqrt(num1, num2);
				break;
				case 6:
					power(num1, num2);
				break;
				case 7:
					mod(num1, num2);
				break;
				case 8:
					average(num1, num2);
				break;
				default :
	            System.out.println("Wrong Operation!");
			}
			System.out.println("Your solution is: " + result);
		}
		// If wrong operation is entered
		else {
			System.out.println("Wrong Operation!!!");
		}

	}
}
@@ -80,16 +80,34 @@
 1, num2;
+%0A%09static int num3;
 %0A%0A%09publi
@@ -460,32 +460,270 @@
 %0A%09public static 
+void squareRoot(int a)%7B%0A%09%09double check;%0A%09%09double result = a / 2;%0A%09%09do %7B%0A%09%09%09check = result;%0A%09%09%09result = (check + (a / check)) / 2;%0A%09%09%7D while ((check - result) != 0);%0A%09%09System.out.println(%22Your solution is: %22 +result);%0A%09%7D%0A%09// public static 
 double sqrt(doub
@@ -722,38 +722,31 @@
 qrt(double a
-, double b
 )%7B%0A%09
+// 
 %09result = Ma
@@ -754,24 +754,27 @@
 h.sqrt(a);%0A%09
+// 
 %09return resu
@@ -770,32 +770,35 @@
 return result;%0A%09
+// 
 %7D%0A%09public static
@@ -832,24 +832,60 @@
 ble b)%7B%0A
+%09%09int y = (int)a;%0A%09%09int x = (int)b;%0A
 %09%09result
  = Math.
@@ -880,25 +880,74 @@
 sult
- 
 = 
-Math.pow(a,b);
+1;%0A%09%09%0A%09%09for(int i=1; i%3C=x; i++ )%0A%09%09%7B%0A%09%09%09%0A%09%09%09result *= y;%0A%09%09%09%0A%09%09%7D
 %0A%09%09r
@@ -1694,33 +1694,33 @@
 Value%22);%0A%09%09%09%09num
-1
+3
  = input.nextDou
@@ -1712,30 +1712,27 @@
 = input.next
-Double
+Int
 ();%0A%09%09%09%7D els
@@ -1885,166 +1885,8 @@
 ();%0A
-%09%09%09%09while (operation==4 && num2 == 0) %7B%0A%09%09%09%09%09System.out.println(%22You can't divide by zero '0'. Enter Value 2 again:%22);%0A%09%09%09%09%09num2 = input.nextDouble();%0A%09%09%09%09%7D%0A%0A
 %09%09%09%7D
@@ -2128,21 +2128,21 @@
 %09%09sq
-rt(num1, num2
+uareRoot(num3
 );%0A%09
@@ -2364,16 +2364,42 @@
 );%0A%09%09%09%7D%0A
+%09%09%09if (operation != 5) %7B%0A%09
 %09%09%09Syste
@@ -2444,16 +2444,21 @@
 esult);%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%09//

work on square root and power operations: eliminated Math library