program to print series of prime numbers using java

后端 未结 6 1703
太阳男子
太阳男子 2021-01-25 01:40

This code is to print the series of prime number up to given limit but when I am trying to execute this,it goes into infinite loop.

import java.io.*;
class a
{
          


        
6条回答
  •  忘掉有多难
    2021-01-25 02:12

    Problem is value of num is always 2 at the start of loop,even if you say num++ again it takes num=2 which is start statement and wont enter into for loop ever,hence so infinite loop.This will Work

    int num=2;
    while(count!=n)  {         
       for(int i=2;i

提交回复
热议问题