// Tyler Rigsby, CSE 142 // Contains several math operations of our own creation public class MyMath { public static void main(String[] args) { System.out.println(pow(2, -3)); System.out.println(sum(15)); } // Returns the result of the power; base to the exponent public static double pow(int base, int exponent) { double result = 1; for (int i = 1; i <= Math.abs(exponent); i++) { result *= base; // or, result = result * base } if (exponent < 0) { return 1.0 / result; } else { return result; } } // Returns the sum of all numbers from 1 to n; also // for numbers divisible by 7, prints the sum through that number // Sample output(15): // // sum through 7 is 28 // sum through 14 is 105 // (returns 120) public static int sum(int n) { int sum = 0; for (int i = 1; i <= n; i++) { sum += i; if (i % 7 == 0) { System.out.println("sum through " + i + " is " + sum); } } return sum; } }