Last active
October 22, 2016 12:53
Star
You must be signed in to star a gist
新・明解Java入門 演習3-16
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_16 { | |
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(); | |
System.out.print("整数値c:"); | |
int c = stdIn.nextInt(); | |
int max = a; | |
int mid = b; | |
int min = c; | |
// もしmaxがmidより小さい場合は入れ替える。 | |
if (max < mid) { | |
int t = max; | |
max = mid; | |
mid = t; | |
} | |
// もしmidがminより小さい場合は入れ替える。 | |
if (mid < min) { | |
int t = mid; | |
mid = min; | |
min = t; | |
} | |
// 再度maxとmidを比較し、maxがmidより小さい場合は入れ替える。 | |
if (max < mid) { | |
int t = max; | |
max = mid; | |
mid = t; | |
} | |
System.out.println(); | |
System.out.println("数字を昇順となるように並び替えました。"); | |
System.out.println("結果は" + min + " < " + mid + " < " + max + "です。"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment