# Guyyzz,the output is not coming-- PLS HELP

• May 31st, 2013, 07:13 AM
Ashish S
Guyyzz,the output is not coming-- PLS HELP
the program is for generating prime numbers. The input would be how many prime number a user wants from the code.

-----------------------------------------------------------------------------------------------------------------

import java.util.*;

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
System.out.println("Enetr the nos of prime numbers");
int number=input.nextInt();
System.out.println("The prime numbers are:");

}

int firstnumber=2;
int count=0;
while(count<nos){
for(int divisor=2;divisor<firstnumber/2;divisor++){
if(firstnumber%divisor!=0)
System.out.println("\t"+firstnumber);
firstnumber++;
}
count++;
}
}
}
• May 31st, 2013, 07:24 AM
angstrem
Re: Guyyzz,the output is not coming-- PLS HELP
Check your for loop's conditions. Analyse when is it true and when is it false.
• May 31st, 2013, 12:26 PM
beansnbacon
Re: Guyyzz,the output is not coming-- PLS HELP
It is way too confusing. Make a separate method to check if a given number is prime and in your method return all prime numbers nos and lower.

Code :

```public boolean isPrime(int x){ for(int z = 2; z < x/2; z++){ if(x%z == 0){ return true; } } return false; }   public void primeNumbers(int x){ for(int z = 0; z <= x; z++){ if(isPrime(z){ System.out.println(z); } } }```
• May 31st, 2013, 12:28 PM
angstrem
Re: Guyyzz,the output is not coming-- PLS HELP
No. Check _manually_ whether you've provided _correct_ "while" condition at for-loop.
• June 1st, 2013, 04:18 AM
Ashish S
Re: Guyyzz,the output is not coming-- PLS HELP
why we cant write "return false" in for loop itself after "else" statement????
• June 1st, 2013, 07:17 AM
angstrem
Re: Guyyzz,the output is not coming-- PLS HELP
By the way, that loop is incorrect. It checks whether a number is not prime. If we write "return" in a loop, will that loop be still correct in all cases?
• June 1st, 2013, 08:01 AM
ewibowo
Re: Guyyzz,the output is not coming-- PLS HELP
I've just corrected some mistakes.

Code :

`...`
• June 1st, 2013, 08:42 AM
copeg
Re: Guyyzz,the output is not coming-- PLS HELP
• June 2nd, 2013, 09:27 AM
Ashish S
Re: Guyyzz,the output is not coming-- PLS HELP
Then it should give the output of that nos. which are not prime numbers. But the output is not coming only, I think the method is not running. Wat to do, pls help!!
• June 3rd, 2013, 02:39 AM
jps
Re: Guyyzz,the output is not coming-- PLS HELP
Quote:

Originally Posted by Ashish S
Then it should give the output of that nos. which are not prime numbers. But the output is not coming only, I think the method is not running. Wat to do, pls help!!

What does this even mean?

If you still have a question, post the current version of the code with the question.