Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Last active October 16, 2016 08:20
Show Gist options
  • Save mokomokohitsuzi/2803a30905c32118a40111042b35c1bd to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/2803a30905c32118a40111042b35c1bd to your computer and use it in GitHub Desktop.
新・明解Java入門 演習3-7
import java.util.Scanner;
public class En3_7 {
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 % 3 == 0) {
//nを3で割った余りが0の場合。
System.out.println("その値は3で割り切れます。");
} else if (n % 3 == 1) {
//nを3で割った余りが1の場合
System.out.println("その値を3で割った余りは1です。");
} else if (n % 3 == 2) {
//nを3で割った余りが2の場合
System.out.println("その値を3で割った余りは2です。");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment