java if與for循環的題
//打印一個4*5的空心長方形
/*
for (int i = 0; i < 5;i++ ) {
if (i == 0 | i == 4) {
System.out.println("*****");
} else {
System.out.println("* *");
}
}
*/
//打印一個4*5的長方形
/*
for (int i = 0; i < 5;i++ ) {
for (int j = 0; j < 4;j++ ) {
System.out.print("*");
}
System.out.println(" ");
}
*/
//1-100以內前5個能被3整除的整數
/*
int a=0;
for (int j = 1; j <= 100; j++ ) {
if (j%3==0) {
System.out.println(j);
a++;
if (a==5) {
break;
}
}
} */
//101~200之間的質數
/*
for (int h = 101;h <= 200; h++ ) {
int a = 0;
for (int g = 2;g < h;g++ ) {
if (h % g == 0) {
a=1;
}
}
if (a == 0) {
System.out.println(h);
}
}
*/
java if與for循環的題