This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes problem with java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem with java code" Watch "problem with java code" New topic
Author

problem with java code

Vinnibabu singu
Ranch Hand

Joined: Aug 19, 2009
Posts: 30
Hello everyone,
I wanted to writte a program to print prime numbers between two given numbers.
The range of numbers should be given through command prompt.
like if we give

> java primeno 4 20

it should display the prime numbers between 4 and 20

I wrote the following code for it


no numbers are being displayed.
please tell me where the problem is and correct it.
thank you
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

First of all, please add some indentation. It's not easy to read this way.

Your flag will remain false if it even one number is not a prime, because the only place you set it to true is at the very start of the method. You should set it to true for each number you want to test; just move the declaration inside the first for-loop.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Vinnibabu singu
Ranch Hand

Joined: Aug 19, 2009
Posts: 30
thank you very much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with java code
 
Similar Threads
Fibonacci
Explain this FFT Radix 2 DIT java code line by line
problem in coding
Out of Memory Exception when using Levenshtein Algorithm
fyi: pre/post increment with exception thrown on the line