Hello
I'm having trouble with a programming project. I understand the problem but I ran out of ideas to resolve the issue. I'm actually relearning java again and practicing before I re-enroll back into a University. Here is my code.
//***************************************************************************** // PP 2.3 Author: Gregory Shavers // // This project will take input from a user and display demographic & personal // information about this person. // //***************************************************************************** import java.util.Scanner; public class JavaApplication7 { public static void main(String[] args) { String Name, College, Petname; int Age; Scanner scan = new Scanner (System.in); System.out.print ("What is your name? " ); Name =scan.nextLine(); System.out.print ("What is your age? " ); Age = scan.nextInt(); System.out.print ("What is your college? " ); College = scan.nextLine(); System.out.print( "What is your pet name? " ); Petname = scan.next(); System.out.println(" \n Hello, my name is " + Name + " and I am " + Age + " years \n old. I'm enjoying my time at " + College + ", through \n I miss my pet " + Petname + " very much!" );
This is the output of my application.
***Start of build***
run:
What is your name? Gregory B Shavers Jr
What is your age? 24
What is your college? What is your pet name? OB
Hello, my name is Gregory B Shavers Jr and I am 24 years
old. I'm enjoying my time at , through
I miss my pet OB very much!
BUILD SUCCESSFUL (total time: 13 seconds)
***End of Build***
As you can see for some reason my *College* and "Petname* varible string comes out into one line. What I want it to do is to output separately. The scanner object should take two *separete* Variables store them. And re output my answers in the sentences below. I know the issue is my nextLine constuctor but I don't know what lines of code to use to fix this. I checked google and found some answers. Some of them code they did didn't make sense to me. I already busted through my old text book but I couldn't find and examples or hint on how to resolve this problem. I even checked this site to find some answers but I could not find any recent post. Would the community bless on some knowledge on how to properly use the scan.nextInt constuctor. I would greatly appericated.
Thanks!
**Happy Coding***