Results 1 to 5 of 5
  1. #1
    Java is offline Member
    Join Date
    May 2015
    Posts
    2
    Rep Power
    0

    Question Concatenating question "I'm a beginner"

    So this is a school project, and I have done it but I don't quite understand the second part! Can anybody guide me?

    "1. Write a program that declares and concatenates various strings. Declare
    strings for your first name, middle initial and last name, along with one
    for your address, city, state and zip. Make an additional string called
    firstLine, which will be a concatenation of first name, space, middle
    initial, period, space, and last name. Assign each of these strings a
    value, and then print the information in the following format:

    First Line (First name Middle initial (period) Last name)
    Address
    City, State
    Zip

    For example:
    John Q. Public
    1234 Any Street
    Cleveland, Ohio
    44101

    2. Now reassign the strings in the same program (Do not create a separately
    compiled program!) and repeat the printout for different information.
    When you are finished, your program will print out two groups as above.

    The information should be placed into the seven separate strings, then
    a first line should be formed by concatenating first name, space, middle
    initial, period, space, and last name. The city and state line should be
    formed by printing city followed by a comma, a space, then the state (NOT
    by concatenation). This is so you can see different ways of making lines."

    and this is what I have so far:

    Concatenating question "I'm a beginner"-javaprint.png

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Concatenating question "I'm a beginner"

    I am not quite certain I understand enough to correctly guide you. I believe the seven strings are first, middle, last, address, city, state, zip. The first time you created a line for each part of the address and assigned it to a variable. The second time I believe you are supposed to simply do it with print statements without creating a new string for each. But I recommend you discuss with your teacher.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Concatenating question "I'm a beginner"

    Quote Originally Posted by Java View Post
    Declare strings for your ... city, state and zip.
    I'd read that as inputting separate Strings for city and state. Not one String for both.

    Quote Originally Posted by Java View Post
    print the information in the following format:
    ...
    City, State
    Zip

    For example:
    ...
    Cleveland, Ohio
    44101
    ...
    The city and state line should be formed by printing city followed by a comma, a space, then the state (NOT by concatenation).
    Do you know the difference between the print(...) and println(...) methods?

    Oh, and post code, not screenshots. BB Code List - Java Programming Forum - Learn Java Programming

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Java is offline Member
    Join Date
    May 2015
    Posts
    2
    Rep Power
    0

    Default Re: Concatenating question "I'm a beginner"

    Thanks for your reply, how about this one? Did I do it right?

    Java Code:
    public class Program2 {
    	
    	   // main method begins execution of Java application
    	   public static void main( String args[] )
    	   {
               // Assign first name, middle name and last name 
    		   String firstName = "John";
    		   String middleName = "Q";
    		   String lastName = "Public";
    		   
    		   // Assign address, city, state and zip code
    		   String address = "11 Street";
    		   String city = "Los Angeles, ";
    		   String state = "CA";
    		   String zipCode = "98765";
    				   
    		   
    		   //Concatenate first name middle name and last name
    		   String firstLine = firstName + " " + middleName + ". " + lastName;
    		   	   
    		   
    		   // Display results 
    		   System.out.println( firstLine );
    	       System.out.println( address );
    	       System.out.print( city );
    	       System.out.println( state );
    	       System.out.println( zipCode );
    	       
    
    	   } // end method main
    
    	} // end class Program2

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Concatenating question "I'm a beginner"

    I don't see code that prints the comma and space in the way specified in the assignment.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Java beginner, trouble with "switch"
    By cupofdoug in forum New To Java
    Replies: 2
    Last Post: 03-11-2013, 10:50 AM
  2. Replies: 0
    Last Post: 12-07-2012, 08:29 AM
  3. Replies: 3
    Last Post: 10-30-2012, 03:06 PM
  4. "Java Programming for the Absolute Beginner"
    By finalstrike777 in forum New To Java
    Replies: 2
    Last Post: 07-12-2011, 12:41 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •