Results 1 to 10 of 10
Thread: input digits- separate
- 11-01-2010, 03:45 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
input digits- separate
hi!
I have a doubt in my code.
For example:
Java Code:1. import java.util.Scanner(); 2. 3. public class Example{ 4. public static void main (String [ ] args){ 5. 6. int dados; 7. 8. Scanner teclado= new Scanner (System.in); 9. System.out.print("Insert numbers:"); // I would like to input separate digits (9 9 9 9) 10. dados=teclado.nextInt(); 11. 12. } 13. }
thanks
- 11-01-2010, 03:50 PM #2
Member
- Join Date
- Nov 2010
- Posts
- 12
- Rep Power
- 0
I think you either need to create additional variables to hold the integer values, or setup an array to hold multiple values from the user input..
- 11-01-2010, 04:04 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
No, I just insert the number and automatically add a space...
Input: 2(automatically space)3(automatically space)4(automatically space)
-
But what will the user have to type in? Something like:
2<enter>
3<enter>
4<enter>
?
- 11-01-2010, 04:28 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 12
- Rep Power
- 0
Then you would need to do something like this i suspect..
Java Code:import java.util.Scanner; public class Example{ public static void main( String args[] ){ Scanner teclado = new Scanner( System.in ); int num1; int num2; int num3; int num4; int num5; System.out.print( "Insert Numbers: "); num1 = input.nextInt(); num2 = input.nextInt(); num3 = input.nextInt(); num4 = input.nextInt(); num5 = input.nextInt(); } }
-
- 11-01-2010, 04:35 PM #7
Member
- Join Date
- Nov 2010
- Posts
- 12
- Rep Power
- 0
I shall shut my noise hole then.
- 11-01-2010, 04:41 PM #8
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
-
- 11-01-2010, 05:23 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 26
So, the display will show -
Insert numbers:
Insert numbers: 2 3 4<Enter>
Then read a String, not an int, and split the String on a space and then parseInt() the individual parts of the String[] you get back.
Similar Threads
-
reversing digits
By gandalf5166 in forum New To JavaReplies: 3Last Post: 03-06-2010, 05:34 PM -
Digits of an integer.
By Allgorythm in forum New To JavaReplies: 8Last Post: 01-01-2010, 03:34 AM -
Should I separate my code into separate files?
By Inks in forum New To JavaReplies: 0Last Post: 03-26-2009, 01:12 AM -
split() by digits
By RobertF in forum New To JavaReplies: 2Last Post: 03-12-2009, 03:16 AM -
sum of digits depreciation
By jleas in forum New To JavaReplies: 13Last Post: 11-09-2008, 02:37 PM
Bookmarks