Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #25259 > unrolled thread

Nothing prints when I compile my code

Started byJohn Stephens <johnnyringo888@gmail.com>
First post2013-09-08 09:06 -0700
Last post2013-09-09 01:48 -0700
Articles 4 — 3 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  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

#25259 — Nothing prints when I compile my code

FromJohn Stephens <johnnyringo888@gmail.com>
Date2013-09-08 09:06 -0700
SubjectNothing prints when I compile my code
Message-ID<ec0481dd-6ec3-4ff7-93de-48d577af8fc0@googlegroups.com>
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?

Here is my code:

//*************************************************************************************************
// Author:	John Stephens			Date: September 7, 2013
// Class: COP 2551               Filename: Homesick.java
// Lab: Lab 1
// Programming Project PP2.3 on Page 109.
// Purpose:  This program prompts and reads a person's name, college, and petname into a paragraph
//*************************************************************************************************

import java.util.Scanner;

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);
    String Name = scan.nextLine();
     
    System.out.println ("Johnny");
    name = scan.nextLine();
    
    System.out.println ("41");
    age = scan.nextInt();
    scan.nextLine();
                
    System.out.println ("FSCJ");
    college = scan.nextLine();
               
    System.out.println ("Sagwa");
    petname = scan.nextLine();
            
    System.out.println ( "Hello, my name is " + name + " and I am " + age + " years " +
                         "old. I'm enjoying my time at, " + college + " though " +
                         "I miss my pet " + petname + " very much!" );
   }
}

[toc] | [next] | [standalone]


#25260

Frommarkspace <markspace@nospam.nospam>
Date2013-09-08 09:50 -0700
Message-ID<l0i9sg$g9n$1@dont-email.me>
In reply to#25259
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.

[toc] | [prev] | [next] | [standalone]


#25261

FromJohn Stephens <johnnyringo888@gmail.com>
Date2013-09-08 09:55 -0700
Message-ID<56ea4544-5c85-475a-9597-795d8954b187@googlegroups.com>
In reply to#25259
On Sunday, September 8, 2013 12:06:35 PM UTC-4, 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?
> 
> 
> 
> Here is my code:
> 
> 
> 
> //*************************************************************************************************
> 
> // Author:	John Stephens			Date: September 7, 2013
> 
> // Class: COP 2551               Filename: Homesick.java
> 
> // Lab: Lab 1
> 
> // Programming Project PP2.3 on Page 109.
> 
> // Purpose:  This program prompts and reads a person's name, college, and petname into a paragraph
> 
> //*************************************************************************************************
> 
> 
> 
> import java.util.Scanner;
> 
> 
> 
> 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);
> 
>     String Name = scan.nextLine();
> 
>      
> 
>     System.out.println ("Johnny");
> 
>     name = scan.nextLine();
> 
>     
> 
>     System.out.println ("41");
> 
>     age = scan.nextInt();
> 
>     scan.nextLine();
> 
>                 
> 
>     System.out.println ("FSCJ");
> 
>     college = scan.nextLine();
> 
>                
> 
>     System.out.println ("Sagwa");
> 
>     petname = scan.nextLine();
> 
>             
> 
>     System.out.println ( "Hello, my name is " + name + " and I am " + age + " years " +
> 
>                          "old. I'm enjoying my time at, " + college + " though " +
> 
>                          "I miss my pet " + petname + " very much!" );
> 
>    }
> 
> }

Thank you!

[toc] | [prev] | [next] | [standalone]


#25266

FromRoedy Green <see_website@mindprod.com.invalid>
Date2013-09-09 01:48 -0700
Message-ID<2q2r29hqpj11qb8gko06jatsf73q4l8fp3@4ax.com>
In reply to#25259
On Sun, 8 Sep 2013 09:06:35 -0700 (PDT), John Stephens
<johnnyringo888@gmail.com> wrote, quoted or indirectly quoted someone
who said :

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

see http://mindprod.com/jgloss/helloworld.html
for the usual things that go wrong with your first program.

Try adding a print at the top so you can at least make sure you
program is starting.

Your prompts look odd.  You should be prompting with field names, not
the data.
-- 
Roedy Green Canadian Mind Products http://mindprod.com
Truth is much too complicated to allow anything but approximations. 
 ~ John von Neumann (born: 1903-12-28 died: 1957-02-08 at age: 53)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web