Last active
October 22, 2016 12:24
-
-
Save mokomokohitsuzi/0c84b406662658d852f49aceda6473e2 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習3-14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class En3_14 { | |
public static void main(String[] args) { | |
Scanner stdIn = new Scanner(System.in); | |
System.out.print("整数値a:"); | |
int a = stdIn.nextInt(); | |
System.out.print("整数値b:"); | |
int b = stdIn.nextInt(); | |
int max = a; | |
int min = b; | |
// もしmaxがminより小さい場合は入れ替える。 | |
if (max < min) { | |
int t = max; | |
max = min; | |
min = t; | |
} | |
// 三項演算子でmaxとminの値が同じか判定する。 | |
System.out.println((max == min) ? "2つの値は同じです。" : "最大値は" + max + "、最小値は" + min + "です。"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment