java求100以內的素數
阿新 • • 發佈:2019-02-06
求100以內的素數,並以5個一行輸出。兩種方式執行
Application: Xiti332_2.java
import java.io.*;
public class Xiti332_2
{
public static void main(String args[])
{
int i,j,k=0;
FirstLoop:
for(i=1;i<100;i++)
{
if(i%2==0)
continue FirstLoop;
for(j=3;j<i;j++)
{
if(i%j==0)
continue FirstLoop;
}
System.out.print(" "+i);
k++;
if(k%5==0)
{System.out.print("/n");}
}
}
}
Applet: Xiti332.java
import java.applet.Applet;
import java.awt.*;
public class Xiti332 extends Applet
{
public void paint(Graphics g)
{
int i,j,p=0,k=0;
FirstLoop:
for(i=1;i<100;i++)
{
if(i%2==0)
continue FirstLoop;
for(j=3;j<i;j++)
{
if(i%j==0)
continue FirstLoop;
}
g.drawString(Integer.toString(i),20+k*30,50+p*30);
if(k>3)
{ p++;k=0;}
else
k++;
}
}
}
Application: Xiti332_2.java
import java.io.*;
public class Xiti332_2
{
public static void main(String args[])
{
int i,j,k=0;
FirstLoop:
for(i=1;i<100;i++)
{
if(i%2==0)
continue FirstLoop;
for(j=3;j<i;j++)
{
if(i%j==0)
continue FirstLoop;
}
System.out.print(" "+i);
k++;
if(k%5==0)
{System.out.print("/n");}
}
}
}
Applet: Xiti332.java
import java.applet.Applet;
import java.awt.*;
public class Xiti332 extends Applet
{
public void paint(Graphics g)
{
int i,j,p=0,k=0;
FirstLoop:
for(i=1;i<100;i++)
{
if(i%2==0)
continue FirstLoop;
for(j=3;j<i;j++)
{
if(i%j==0)
continue FirstLoop;
}
g.drawString(Integer.toString(i),20+k*30,50+p*30);
if(k>3)
{ p++;k=0;}
else
k++;
}
}
}