Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Scanner (death loop)

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Scanner (death loop)

    hello,

    I am a new java programmer, i am learning the basics at my school. I am using the program Jcreator and JDK 1.7
    Scanner does not go blue, and i don't think the import is working, also when i build the code i get no errors, when i run it it says process completed but nothing comes up but the number 12? The program is still running i cannot rerun or rebuild it.
    My code is the following

    import java.io.*;
    import java.util.*;
    public class Tester
    {
    public static void main( String args[] )
    {
    Scanner kbReader = new Scanner(System.in);
    System.out.print(“12”);
    int i = kbReader.nextInt( );
    System.out.println(3 * i);

    }
    }



    plz help!!!!


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Scanner (death loop)

    I see a big problem with the quote characters you're using. Java will only recognize the basic quote symbol, ", for both opening and closing quotes, not the specific opening and closing quotes you use. So I suggest that you change this:
    System.out.print(“12”);

    to this:
    System.out.print("12");  // *** see the difference?

  3. The Following User Says Thank You to curmudgeon For This Useful Post:

    F6e9a (November 11th, 2012)

  4. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Scanner (death loop)

    Ok, i see. I made the changes, and i still don't get 36 as answer, but i get 12? the program is still not completely over it loops?

  5. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Scanner (death loop)

    I wouldn't expect the answer to be 36 unless you enter 12 in the console window since the answer will depend entirely on the value of i that you enter when the program runs and i alone.

  6. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Scanner (death loop)

    ok, thanks i got it. it finally makes sense, its a input file. haha this made my day!!!

  7. #6
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Scanner (death loop)

    No, there are no files involved in your code as you've posted it. There is an InputStream however supplied by System.in that is read by the Scanner, and perhaps this is what you meant.

  8. The Following User Says Thank You to curmudgeon For This Useful Post:

    F6e9a (November 11th, 2012)

  9. #7
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Scanner (death loop)

    Thanks problem solved i need to enter something in the console window i get it my java book didn't explain that very well. Problem solved.

  10. #8
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 139 Times in 134 Posts

    Default Re: Scanner (death loop)

    Glad you've got it figured out!

Similar Threads

  1. For loop, the first command in the loop does not get executed the 2nd time..
    By lina_inverse in forum Loops & Control Statements
    Replies: 1
    Last Post: October 16th, 2012, 10:00 PM
  2. Converting a while loop to a for loop and a for loop to a while loop.
    By awesom in forum Loops & Control Statements
    Replies: 3
    Last Post: February 26th, 2012, 08:57 PM
  3. Scanner help
    By sp11k3t3ht3rd in forum Java Theory & Questions
    Replies: 3
    Last Post: June 22nd, 2011, 12:55 PM
  4. Jumps over one scanner in if else loop
    By MikalD in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 5th, 2011, 09:34 AM
  5. Conways Game of Life. Long Death option. Please help..
    By byako in forum What's Wrong With My Code?
    Replies: 8
    Last Post: March 9th, 2011, 08:49 AM