Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Created October 24, 2016 12:34
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/5c7d13495e6a3e4cbd868402be98be1d to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/5c7d13495e6a3e4cbd868402be98be1d to your computer and use it in GitHub Desktop.
新・明解Java入門 演習4-1
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