Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Created October 12, 2016 14:27
Show Gist options
  • Save mokomokohitsuzi/ccfffa5b18d70d3c10307b342012af39 to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/ccfffa5b18d70d3c10307b342012af39 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習3-5
import java.util.Scanner;
public class En3_5 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
System.out.print("正の整数値:");
int n = stdIn.nextInt();
if (n <= 0) {
// nが負の値の場合
System.out.println("正でない値が入力されました。");
} else if (n % 5 == 0) {
// nの値が5で割り切れる場合
System.out.println("その値は5で割り切れます。");
} else if (n % 5 != 0) {
// nの値が5で割り切れない場合
System.out.println("その値は5で割り切れません。");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment