编写程序yongjava脚本写显示1到100之间的素数每行10个元素

2024-11-06 15:31:04
推荐回答(2个)
回答1:

package a;

public class sushu {
public static void main(String[] args) {
int s=0;
for (int i =2; i <=100; i++) {
for (int j =2; j <=i; j++) {
if(i==j){
System.out.print(i+" ");
s++;
if(s%10==0){
System.out.println();
}
}
if(i%j==0){
break;
}
}
}
}
}

回答2:

public class Text{
public static void main(String[] args){

for(int i=1;i<=100;i++){

boolean issu=true;
for(int j=1;j
if(i%j==0){

issu=false;
break;

}
}

if(issu)

System.out.println(i);

}

}

}