Created
October 26, 2016 11:50
-
-
Save mokomokohitsuzi/ecbd6f8fd2fd3dbe872b0a7a46a724b0 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習4-3
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 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