2015年4月16日木曜日

3つの整数を入力して最大値を表示するjavaプログラムパターン2

Javaバイブルシリーズ Java入門 P143 応用課題5.3.1


------
import java.io.*;
public class Maximum1 {
 public static void main(String[] args) throws IOException {
 
  final String MAX_MESSAGE = "最大値は";
  String max = "";
 
  BufferedReader br =
          new BufferedReader(new InputStreamReader(System.in));
 
 
  System.out.print("xを入力>");
  int x = Integer.parseInt(br.readLine());
  System.out.print("yを入力>");
  int y = Integer.parseInt(br.readLine());
  System.out.print("zを入力>");
  int z = Integer.parseInt(br.readLine());
 
  int maxValue = x;
  if (y > x) {
   maxValue = y;
     }
  if (z > y && z > x) {
   maxValue = z;
  }
  System.out.println(MAX_MESSAGE + maxValue);


 }
}
------

実行結果
------
>java Maximum1
xを入力>4
yを入力>3
zを入力>5
最大値は5
 -- Press any key to exit (Input "c" to continue) --
------

0 件のコメント:

コメントを投稿