Printing prime number from 1 to 100

前端 未结 7 1548
情书的邮戳
情书的邮戳 2021-02-11 10:12

This program is supposed to output the prime numbers between 1 and 100. Will anyone please explain me the flow the programme below? I am having difficulty in writing the progra

相关标签:
7条回答
  • 2021-02-11 10:55
    public class Prime {
        public static void main(String arg[])
        {
            int count=0;
    
            for(int i=2;i<100;i++)
            {
                for(int j=2;j<i;j++)
                {
                    if(i%j!=0)
                    {
                        count++;
                        if(count==i-2)
                        {
                            System.out.print(i+" ");
                        }
                    }
                }
                count = 0;
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题