Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-24-2007, 08:55 PM
Member
 
Join Date: Dec 2007
Posts: 5
new_1 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-24-2007, 10:04 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,144
hardwired is on a distinguished road
Let's see what you did.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-24-2007, 10:19 PM
Member
 
Join Date: Dec 2007
Posts: 5
new_1 is on a distinguished road
take input from user
well, the code was long, but even the example below didnt work.
Code:
public class Main { public static void main(String[] args) { Scanner input = new Scanner( System.in ); int i=input.nextInt(); } }
and of course class java.util.Scanner is imported above.
ill appreciate immediate help.
thanks.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-24-2007, 11:11 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,144
hardwired is on a distinguished road
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.
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); } }
When you have trouble you can always throw a small test app together to explore things.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-25-2007, 03:44 AM
Member
 
Join Date: Dec 2007
Posts: 5
new_1 is on a distinguished road
hi,
ive copied the code you provided above and tried to run it,
same problem arises!
thanks.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 12-25-2007, 03:52 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Quote:
Originally Posted by new_1 View Post
hi,
ive copied the code you provided above and tried to run it,
same problem arises!
thanks.
Are you sure you entered it correctly? I copied and ran his code and it worked just fine for me.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 12-25-2007, 08:38 AM
Member
 
Join Date: Dec 2007
Posts: 5
new_1 is on a distinguished road
Thanks, it worked now. I just wasnt familiar with new IDE i had.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the User Name Java Tip java.lang 0 04-04-2008 03:43 PM
Prompting user input of a string. apfroggy0408 New To Java 3 03-09-2008 07:23 PM
Creating a dialog to input user/password prfalco New To Java 4 02-18-2008 08:03 AM
New User TKI5 New To Java 0 12-13-2007 02:13 AM
how to take input and verify input in Java programs bilal_ali_java Advanced Java 0 07-21-2007 09:46 AM


All times are GMT +3. The time now is 07:38 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org