Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Created October 26, 2016 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokomokohitsuzi/ecbd6f8fd2fd3dbe872b0a7a46a724b0 to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/ecbd6f8fd2fd3dbe872b0a7a46a724b0 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習4-3
import java.util.Scanner;
public class En4_3 {
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;
}
// nがmaxと同じ値になるまでdo文で+1する。
int n = min;
do {
System.out.print(n);
n = n + 1;
System.out.print(" ");
} while (max != n);
// 上記では最大値と同じになった時点でdo文を抜けるため、
// 最後にnの値を表示する。
System.out.println(n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment