Results 1 to 7 of 7
Thread: cant take input from user
- 12-24-2007, 07:55 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 5
- Rep Power
- 0
cant take input from user
hi,
my application was successfully compiled, but when i tried to run it, kept running..
this happens at the step when im taking input from user.
i use a scanner object to take input from user.
i imported all java.util classes.
What could be the problem???
plz help ASAP.
thnx.
- 12-24-2007, 09:04 PM #2
Let's see what you did.
- 12-24-2007, 09:19 PM #3
Member
- Join Date
- Dec 2007
- Posts
- 5
- Rep Power
- 0
take input from user
well, the code was long, but even the example below didnt work.
Java Code:public class Main { public static void main(String[] args) { Scanner input = new Scanner( System.in ); int i=input.nextInt(); } }
ill appreciate immediate help.
thanks.
- 12-24-2007, 10:11 PM #4
Yes, using nextInt with the System.in will cause the jvm to move along after the first use (of something like nextInt) without blocking for user input. Try nextLine instead.
Java Code:import java.util.*; public class Test { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("enter an int"); int n = Integer.parseInt(scanner.nextLine()); System.out.println("you entered " + n); System.out.println("enter a String"); String line = scanner.nextLine(); System.out.println("you entered " + line); } }
- 12-25-2007, 02:44 AM #5
Member
- Join Date
- Dec 2007
- Posts
- 5
- Rep Power
- 0
hi,
ive copied the code you provided above and tried to run it,
same problem arises!
thanks.
- 12-25-2007, 02:52 AM #6
- 12-25-2007, 07:38 AM #7
Member
- Join Date
- Dec 2007
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
How to get the User Name
By Java Tip in forum java.langReplies: 0Last Post: 04-04-2008, 02:43 PM -
Prompting user input of a string.
By apfroggy0408 in forum New To JavaReplies: 3Last Post: 03-09-2008, 06:23 PM -
Creating a dialog to input user/password
By prfalco in forum New To JavaReplies: 4Last Post: 02-18-2008, 07:03 AM -
New User
By TKI5 in forum New To JavaReplies: 0Last Post: 12-13-2007, 01:13 AM -
how to take input and verify input in Java programs
By bilal_ali_java in forum Advanced JavaReplies: 0Last Post: 07-21-2007, 08:46 AM
Bookmarks