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.
Code :
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.");
}
}
}
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
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?
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!
Re: Showrt program will compile but nothing happens when I run it.
Quote:
Originally Posted by
learningjavanow
... I see now whats wrong. ...
... and you were going to tell us, right?
Re: Showrt program will compile but nothing happens when I run it.
Quote:
Originally Posted by
curmudgeon
... 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.
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!