Skip to content

Instantly share code, notes, and snippets.

@hiyorineko
Last active December 23, 2015 12:49
Show Gist options
  • Save hiyorineko/6638431 to your computer and use it in GitHub Desktop.
Save hiyorineko/6638431 to your computer and use it in GitHub Desktop.
インデントをなおしてみた
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+"は素数じゃないです");
}
}
}
@hiyorineko
Copy link
Author

1:(開始)

2:[素数か判断したい数を変数Bに代入]

3:[true,false判定に使用するboolean型変数"flag"を初期値trueで代入]

4:[素数なので2B-1の数値の分繰り返す]

5:<ループカウンタiがB-1以下かどうか>→No→11行目に

6:Yes

7:[ループカウンタが2
B-1なのでBをループカウンタで割ってみる]

8:<B%i!=0かどうか>→No→[変数flagをfalseにする]

9:Yes

10:[4行目に戻る]

11:<変数flagがtrueかどうかを調べる>→No→["Bは素数ではありません"と表示する]→[14行目に]

12:Yes

13:["Bは素数です"と表示する]

14:(終了)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment