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 7 of 7

Thread: Showrt program will compile but nothing happens when I run it.

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Showrt program will compile but nothing happens when I run it.

    This program will compile, but nothing happens when I run it, can you guys see why? It is supposed to ask for a number on the command line, and then check if the number is less than 5. Thanks for the help.

    import java.util.*;
     
    class ReadNumber {
        public static void main(String[] args) {
    	Scanner keyboard = new Scanner(System.in);
    	int a = keyboard.nextInt();
    	if (a < 5) {
    	    System.out.println("The number is less than five.");
    	}
        }
    }


  2. #2
    Member
    Join Date
    Dec 2012
    Posts
    33
    My Mood
    Confused
    Thanks
    2
    Thanked 2 Times in 1 Post

    Default Re: Showrt program will compile but nothing happens when I run it.

    it works! You just have to insert the number in the console, if you want to make it clearer just add something like System.out.println("insert the number here ->") before of the scanner

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Showrt program will compile but nothing happens when I run it.

    Can you explain how you execute the program and what the program does when it starts executing?
    Does the program end immediately, or is it waiting for something to happen? Like: for the user to enter a number.

    Do you type in the number it is waiting for?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Showrt program will compile but nothing happens when I run it.

    Thanks for the quick replies guys, I see now whats wrong. I feel so stupid hehe, merry christmas and thanks!

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

    Default Re: Showrt program will compile but nothing happens when I run it.

    Quote Originally Posted by learningjavanow View Post
    ... I see now whats wrong. ...
    ... and you were going to tell us, right?

  6. #6
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Showrt program will compile but nothing happens when I run it.

    Quote Originally Posted by curmudgeon View Post
    ... and you were going to tell us, right?
    It was as the two people above me wrote, sorry for not making that clear. The program does run, but it is waiting for the user to input a number. But I do not ask the user for a number, that is why it seemed like nothing happened.

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

    Default Re: Showrt program will compile but nothing happens when I run it.

    Thanks for informing us. Don't lose heart as you're not the first nor last to fall into this trap. Welcome to the javaprogrammingforums.com by the way!

Similar Threads

  1. Replies: 1
    Last Post: November 2nd, 2012, 04:16 PM
  2. Please compile this program and see if it gives you an error
    By Programming_Hobbyist in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 2nd, 2012, 01:36 PM
  3. My program will compile but wont run
    By joshp1993 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 23rd, 2012, 07:45 AM
  4. anagram program wont compile please help
    By Rusak in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 26th, 2011, 06:23 PM
  5. Replies: 2
    Last Post: January 7th, 2011, 09:10 PM