• Post Reply Bookmark Topic Watch Topic
  • New Topic

Take multiple inputs in a single line.  RSS feed

 
Ketan Sethi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to take input in the following way:
Sample Input 1
3
45 3 14

Sample Input 2
5
12 34 5 56 7

The first line is the number of test cases and the second line is the corresponding values for the test cases.
Please give me the java code for taking multiple inputs in the single line separated by a space.
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ketan, Welcome to the Ranch !!!

What have you tried? We are not coding machine to provide you code but to help if someone have a problem..
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ketan, Welcome to the Ranch !!!

What have you tried?
 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please avoid this.
 
Ketan Sethi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am submitting my code in SPOJ(Sphere online judge) for Problem: PRIME1 but it is showing runtime error but the code is working fine in my system
Here are the required items:

Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers!

Input

The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.

Output

For every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.

Example

Input:
2
1 10
3 5

Output:
2
3
5
7

3
5

 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What isn't working for you?
 
Ketan Sethi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i run this code on my computer it works fine but when i run this code in www.ideone.com it shows me runtime error.I've to submit this code in SPOJ website but SPOJ uses www.ideone.com to compile and execute and my code is giving runtime error there.Here is the output which i got on running my code:

Standard input is empty
stdout
Standard output is empty

stderr
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at Prime.main(Main.java:15)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!