Last active
October 10, 2016 11:53
-
-
Save mokomokohitsuzi/558a35611fde5ef4aa90ed5b5027ccc7 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習3-2
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 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