// Quiz2.java // // In Physics, we learn that the Power (P, in watts) // equals the square of the current (I, in amps) times // the resistance (R, in ohms). That is, P = I^2 * R. // Write a Java program which reads in two doubles, the power // in watts and the resistance in ohms, and prints out the // current in amps. // Your program should handle the two impossible cases: first, // if R equals 0 ohms (since this would divide by zero). // Second, if P/R is negative (since this would make I an // imaginary number!). class Quiz2 { public static void main(String[] args) { // your code here! } /////////////////////////////////// // readString, readInt, readDouble /////////////////////////////////// public static String readString() { java.io.InputStreamReader isr = new java.io.InputStreamReader(System.in); java.io.BufferedReader d = new java.io.BufferedReader(isr); try { return d.readLine(); } catch (Exception e) { return "error"; } } public static int readInt() { return Integer.parseInt(readString()); } public static double readDouble() { return Double.valueOf(readString()).doubleValue(); } }