// 2辺の長さから斜辺の長さを求めるプログラム import java.io.*; // おまじない class Pytha2 { public static void main(String[] args) throws IOException { String str; double x, y; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("1辺の長さを入力して下さい。"); str = br.readLine(); x = Double.parseDouble(str); System.out.println("もう1辺の長さを入力して下さい。"); str = br.readLine(); y = Double.parseDouble(str); // 入力された2辺 x, y から斜辺の長さ z を求める double z = pytha(x,y); System.out.println("斜辺の長さは " + z + " です。"); System.out.printf("斜辺の長さは %.1f です。", z ); } // 斜辺の長さを求めるメソッド(実は hypot() を使えば一発) // Pythagorasの定理:Pythagorean theorem、斜辺:hypotenuse static double pytha( double x, double y ) { return( Math.sqrt( x*x + y*y ) ); } } // end of Pytha2.java