Prime Number Generator Logic

后端 未结 15 2223
旧时难觅i
旧时难觅i 2021-01-07 04:10

I am supposed to make a class PrimeNumberGenerator which has a method nextPrime that will print out all prime numbers up to a number the user input

15条回答
  •  时光说笑
    2021-01-07 05:00

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    import javax.xml.soap.Node;
    
    public class mainone {
    
     public static void main(String args[]){
    
        int[] primenumber=new int[13];
    
        for(int a=2,j=0;a<=14;a++,j++){
            primenumber[j]=a;
    
        }
    
        for(int b=1;b<13;b++){
            int d=primenumber[b];
            if(d%2==0){
                primenumber[b]=0;
            }
    
            for(int c=2;c<13;c++){
                int e=primenumber[c];
                if(e>0){
                    for(int f=c+1;f<13;f++){
                        int g=primenumber[f];
                        if((g>0)&(g%e==0)){
                            primenumber[f]=0;
                        }
    
    
                    }
                }
            }
        }
    
    
        for(int j=0;j<13;j++){
            System.out.println(primenumber[j]);
        }
         }
    
     }
    

提交回复
热议问题