Nothing prints when I compile my code

J

John Stephens

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!" );
}
}
 
M

markspace

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.
 
J

John Stephens

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!
 
R

Roedy Green

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top