用java找出1-100内所有素数输入到屏幕上并将非素数的和也输入到屏幕上

[复制链接]
查看11 | 回复2 | 2013-10-22 22:33:49 | 显示全部楼层 |阅读模式
public class baidu1 { public static void main(String args[]) {int n=0;for(int i=3;i<=100;i+=2){ int q=(int)Math.sqrt(i); boolean isPrime=true; for(int j=2;j<=q;j++) {
if(i%j==0) isPrime=false; } if(isPrime==true) {
Syst...
回复

使用道具 举报

千问 | 2013-10-22 22:33:49 | 显示全部楼层
#include "stdio.h"void main(){printf("---------\n");int i,j,check;for( i=1;i<=100;i++){check=1;for(j=2;j<i;j++)if(!(check=i%j))break;if(check) printf("%d\n",i);}}...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行