Created
October 24, 2016 12:34
-
-
Save mokomokohitsuzi/5c7d13495e6a3e4cbd868402be98be1d to your computer and use it in GitHub Desktop.
新・明解Java入門 演習4-1
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_1 { | |
public static void main(String[] args) { | |
Scanner stdIn = new Scanner(System.in); | |
// ループ用変数の作成 | |
int retry; | |
do { | |
System.out.print("整数値:"); | |
int n = stdIn.nextInt(); | |
if (n > 0) { | |
System.out.println("その値は正です。");// nが0より大きい場合 | |
} else if (n < 0) { | |
System.out.println("その値は負です。");// nが0より小さい場合 | |
} else { | |
System.out.println("その値は0です。"); // nが0の場合 | |
} | |
System.out.println(); | |
System.out.print("もう一度? 1…YES 2…NO:"); | |
retry = stdIn.nextInt(); | |
} while (retry == 1); // retryが1の場合、ループする。 | |
System.out.println("終了します。"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment