Results 1 to 6 of 6
Thread: Take two inputs in single line
- 12-24-2010, 11:01 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 9
- Rep Power
- 0
Take two inputs in single line
I want to take two integer inputs
both the inputs must be in same line
BuferedReader br = new BufferedReader(new InputStreamReader(System.in));
int no1=Integer.parseInt(br.readLine());
int no2=Integer.parseInt(br.readLine());
now i give value of no1 and no2 in a single line then how can we read it
-
You can use a Scanner object and get the int tokens one at a time or you can split the line using String#split(regex) where regex is a regular expression that represents the delimiter that is between your two numbers (it could be as simple as a space String " "). You'll then need to parse the resulting Strings to int using Integer.parseInt(...).
- 12-24-2010, 04:00 PM #3
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
Java Code:import java.util.Scanner; public class Read2Integers{ public static void main(String[] args){ Scanner input = new Scanner( System.in ); while( input.hasNextInt() ){ int num = input.nextInt(); System.out.println("strLine: " + num); } input.close(); } }
- 12-25-2010, 01:08 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
This is not good. Rather posting code encourage them to write code themselves. :)
And also your code not doing what OP needs.
- 12-25-2010, 01:43 AM #5
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
if he knew what fubarable was about this would be no problem???
- 12-25-2010, 01:56 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
hmm, at least it's relevant then.
Similar Threads
-
Can I do SCEA ? Please give your inputs.
By senorita2007 in forum Java CertificationReplies: 1Last Post: 07-23-2010, 06:30 AM -
Arrays and Null inputs
By Desmond in forum New To JavaReplies: 4Last Post: 07-21-2010, 06:23 AM -
Someone plz help... how to block inputs
By waklo99 in forum New To JavaReplies: 4Last Post: 03-15-2010, 06:44 AM -
How to create this if many inputs?
By sarahannel123 in forum New To JavaReplies: 3Last Post: 05-18-2008, 04:22 PM -
Date Inputs
By hiranya in forum AWT / SwingReplies: 3Last Post: 11-06-2007, 05:11 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks