Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #25260
| From | markspace <markspace@nospam.nospam> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Nothing prints when I compile my code |
| Date | 2013-09-08 09:50 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <l0i9sg$g9n$1@dont-email.me> (permalink) |
| References | <ec0481dd-6ec3-4ff7-93de-48d577af8fc0@googlegroups.com> |
On 9/8/2013 9:06 AM, John Stephens wrote:
> Another Homework assignment for College Intro to Java course. I am
> having a disconnect with what the issue is. It compiles fine but does
> not print. Hints anyone?
>
It's because you didn't tell it to print anything. Look at the code,
you read the input (call 'nextLine' on the Scanner) before you print
anything. I'd suggest you add a prompt before each use of a scanner
method to give you a hint when the scanner is waiting for input.
Here's an example:
> public class Homesick
> {
>
//----------------------------------------------------------------------------------------------
> // Reads a character string from the user and prints it.
>
//----------------------------------------------------------------------------------------------
> public static void main (String[] args)
> {
> String name, college, petname;
> int age;
> Scanner scan = new Scanner (System.in);
System.out.println( "Enter your name:" ); // add this
> String Name = scan.nextLine();
>
> System.out.println ("Johnny");
Then you will see some output before the program waits. Add an
appropriate println before each use of a scanner method and the program
will be easier to use.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Nothing prints when I compile my code John Stephens <johnnyringo888@gmail.com> - 2013-09-08 09:06 -0700 Re: Nothing prints when I compile my code markspace <markspace@nospam.nospam> - 2013-09-08 09:50 -0700 Re: Nothing prints when I compile my code John Stephens <johnnyringo888@gmail.com> - 2013-09-08 09:55 -0700 Re: Nothing prints when I compile my code Roedy Green <see_website@mindprod.com.invalid> - 2013-09-09 01:48 -0700
csiph-web