Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Last active October 10, 2016 11:53
Show Gist options
  • Save mokomokohitsuzi/558a35611fde5ef4aa90ed5b5027ccc7 to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/558a35611fde5ef4aa90ed5b5027ccc7 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習3-2
import java.util.Scanner;
public class En3_2 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
// 整数Aの読み込み
System.out.print("整数A:");
int seia = stdIn.nextInt();
// 整数Bの読み込み
System.out.print("整数B:");
int seib = stdIn.nextInt();
// もし入力値が-の整数である場合、注意文を促す。
if (seia <= 0) {
System.out.println("整数は正の値を入力してください。");
} else if (seib <= 0) {
System.out.println("整数は正の値を入力してください。");
} else {
// 整数A÷整数Bで割り切れる場合は、約数。それ以外は約数ではない判断。
if (seia % seib == 0) {
System.out.println("BはAの約数です。");
} else {
System.out.println("BはAの約数ではありません。");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment