Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default How can I put another word in the statement after i have inserted the variable

    This problem is probably very simple but no solutions are coming to mind. I want to add Miles per gallon or something related after the actual number of miles the car gets.
    Java Code:
    System.out.println("The 1970 VW Bug averaged: " + bug70);
    I want it to show "The 1970 VW Bug averaged 31.8 mpg." but the only thing I get is "...Bug averaged 31.8" Can anyone point me in the right direction?

  2. #2
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default Re: How can I put another word in the statement after i have inserted the variable

    Fixed it. Don't worry about responding.

  3. #3
    sabre150 is offline Member
    Join Date
    Jul 2012
    Location
    Earth
    Posts
    75
    Rep Power
    0

    Default Re: How can I put another word in the statement after i have inserted the variable

    Quote Originally Posted by Biscuit Tickler View Post
    This problem is probably very simple but no solutions are coming to mind. I want to add Miles per gallon or something related after the actual number of miles the car gets.
    Java Code:
    System.out.println("The 1970 VW Bug averaged: " + bug70);
    I want it to show "The 1970 VW Bug averaged 31.8 mpg." but the only thing I get is "...Bug averaged 31.8" Can anyone point me in the right direction?
    Either
    Java Code:
    System.out.println("The 1970 VW Bug averaged: " + bug70 + " mpg");
    or preferred

    Java Code:
    System.out.printf("The 1970 VW Bug averaged: %d mpg\n", bug70);
    if 'bug70" is a String not a number then replace %d with %s. For this last approach check out the class java.util.Formatter.

Similar Threads

  1. Replies: 7
    Last Post: 02-14-2012, 10:12 AM
  2. data not inserted in tables
    By me.anchit in forum Advanced Java
    Replies: 6
    Last Post: 09-30-2011, 03:02 PM
  3. Data not inserted into an object
    By LoViNgHeArTy in forum New To Java
    Replies: 11
    Last Post: 06-28-2011, 05:51 AM
  4. count inserted line in database
    By tedy2808 in forum New To Java
    Replies: 3
    Last Post: 08-16-2010, 10:57 AM
  5. Word comparison in a Statement
    By jayz in forum New To Java
    Replies: 1
    Last Post: 08-08-2009, 06:34 AM

Posting Permissions

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