2015年4月16日木曜日

3つの整数を入力して最小値を表示するjavaプログラム

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

------
import java.io.*;
public class Minimum {
 public static void main(String[] args) throws IOException {
 
  final String MIN_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 minValue = x;
  if (y < x) {
   minValue = y;
     }
  if (z < y && z < x) {
   minValue = z;
  }
  System.out.println(MIN_MESSAGE + minValue);


 }
}
------

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

0 件のコメント:

コメントを投稿