Last active
December 23, 2015 12:49
-
-
Save hiyorineko/6638431 to your computer and use it in GitHub Desktop.
インデントをなおしてみた
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
public class Check11{ | |
public static void main(String[] args){ | |
//変数宣言 | |
int B = 11;//素数かどうか判断される数字 | |
boolean flag=true;//trueなら素数 falseなら素数じゃないにしたい | |
//調べる | |
for(int i=2;i<=B-1;i++){//B-1までの数を全部調べたい | |
if(B%i==0){ | |
flag = false; //割り切れたらflagをfalseにする | |
} | |
} | |
//表示する | |
if(flag == true){ | |
System.out.println(B+"は素数です"); | |
}else{ | |
System.out.println(B+"は素数じゃないです"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1:(開始)
↓
2:[素数か判断したい数を変数Bに代入]
↓
3:[true,false判定に使用するboolean型変数"flag"を初期値trueで代入]
↓
4:[素数なので2
B-1の数値の分繰り返す]B-1なのでBをループカウンタで割ってみる]↓
5:<ループカウンタiがB-1以下かどうか>→No→11行目に
↓
6:Yes
↓
7:[ループカウンタが2
↓
8:<B%i!=0かどうか>→No→[変数flagをfalseにする]
↓
9:Yes
↓
10:[4行目に戻る]
11:<変数flagがtrueかどうかを調べる>→No→["Bは素数ではありません"と表示する]→[14行目に]
↓
12:Yes
↓
13:["Bは素数です"と表示する]
↓
14:(終了)