import java.util.*; import java.io.*; import java.lang.Math; public class BAMsupport { static Scanner keyboard= new Scanner(System.in); // Create scanner object for keyboard input. //// I/O METHODS // public static void say( String s ) { System.out.println( s ); } public static void say( int i ) { System.out.println( i ); } public static void say( double d ) { System.out.println( d ); } public static void saywhat( String s, int what ) { say( s + what ); } public static void saywhat( String s, double what ) { say( s + what ); } public static int askint( String prompt ) { say( prompt + " " ); // NOTE: Not println return keyboard.nextInt(); } public static double askd( String prompt ) { say( prompt + " " ); return keyboard.nextDouble(); } public static String asks( String prompt ) { say( prompt + "..." ); return keyboard.next(); } //// Methods to display arrays (of various types). //// public static void showarray( int a[], int m ) { for (int j=0; j 0) return x * pow( x, p-1 ); // x * x^(p-1) else { say( "ERROR: Negative power. pow( " +x+ "," +p+ ")" ); return 0; } } public static double abs( double x ) { return (x < 0) ? -x : x; // Return |x| } public static double pow( double x, int p ) { if (p == 0) return 1; // x^0 is 1 else if (p > 0) return x * pow( x, p-1 ); // x * x^(p-1) else return 1.0 / pow( x, abs(p) ); // p < 0 ... return 1 / x^|-p| } public static double pow( double x, double p ) { if (p == 0) return 1; // x^0 is 1 else if (p == 1) return x; // x * x^(p-1) else if (p > 1) return x * pow( x, p-1 ); // x * x^(p-1) else if (p<0) return 1.0 / pow( x, abs(p) ); // p < 0 ... return 1 / x^|-p| else if (p == 0.5) return Math.sqrt( x ) ; // Special case for sqrt. else // (p is between zero and 1) { say( "SORRY, fractional powers have not yet been implemented: pow( " +x+ "," +p+ ") will return zero." ); return 0; } } }