Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Last active October 22, 2016 12:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mokomokohitsuzi/7d4dad60e2ee7e4f43787771711b47b9 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習3-16
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