my dog learned polymorphism*
The moose likes Beginning Java and the fly likes SPOJ - PRIME, got error java.util.NoSuchElementException on ideone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "SPOJ - PRIME, got error java.util.NoSuchElementException on ideone" Watch "SPOJ - PRIME, got error java.util.NoSuchElementException on ideone" New topic
Author

SPOJ - PRIME, got error java.util.NoSuchElementException on ideone

Murari Madkyto
Greenhorn

Joined: May 13, 2012
Posts: 5
Hello guys, I just begin to learn algorithm, and I decide to practice in SPOJ.... I am in "PRIME1" problem for generete prime number from other typical range of number.

this is my code :



I try this code in my IDE (netbeans) and it can run, but when I submitted in spoj, it show runtime error = NZEC, and when I try in ideone.com it show :


I dont understand about this error, could you tell me how to solve this error ? please....

thank you.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Welcome to the ranch Murari.

Murari wrote: and when I try in ideone.com it show :
view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped

Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1585)
at Main.main(Main.java:10)



I dont understand about this error, could you tell me how to solve this error ? please....

thank you.


Yes, I will tell you how to solve it. Go to ideone.com. Read carefully how to use the online IDE. Then provide the correct input for your stdin stream, and then click on run. I just tried it and I am able to successfully execute the given code. You have to read it carefully.

Having said that, I have a question for you. Have you just copied it from the net or have you thought about the logic and then written the class yourself?


~ Mansukh
Murari Madkyto
Greenhorn

Joined: May 13, 2012
Posts: 5
Mansukhdeep Thind wrote:
Having said that, I have a question for you. Have you just copied it from the net or have you thought about the logic and then written the class yourself?


O my God, that's my wrong, thank you mansukh, it works in ideone... but when i try in spoj, the runtime error : NZEC still show. I make this code by myself base on my understanding about Sieve of Eratosthenes in this site : http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes .
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
The first thing to do is get rid of ideone, which is not helping you at all. Run that code from the command line, or get a real IDE like Eclipse or NetBeans. At the beginner’s stage the command line is better.
Next, realise that the Sieve of Eratosthenes is designed to work from numbers starting 1. Your app ran happily for 12345 23456 and confidently told me that 23231 is prime, which it isn’t. It is 11 × 2111. 2111 is prime, however. If you want to run a Sieve, you need to start from 1 (or 0, then the array index can match the value). Remember 1 does not count, and 0 divides by every other number, so the smallest prime number is 2. Fill a boolean[] with true, set 0–1 to false, then iterate the array from every value which is still true, making all its multiples false.
You can use a BitSet instead of an array, if you prefer. I have a Sieve implementation which took approx 0.1sec to check primes up to 2200000, so it is not slow.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SPOJ - PRIME, got error java.util.NoSuchElementException on ideone