Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25
  1. #21
    mc1234 is offline Member
    Join Date
    Sep 2011
    Posts
    24
    Rep Power
    0

    Default Re: Seconds Left to Live

    Quote Originally Posted by Solarsonic View Post
    I honestly never use printf(), since I find println() much easier.

    If I were doing this then I would change

    Java Code:
    System.out.printf(" You have been alive for %,d seconds.\n", secondslived);
    System.out.println("The average human life is 2,500,000,000 seconds");
    System.out.printf("You have" + (averagelife - secondslived) + " seconds to live!");
    to

    Java Code:
    System.out.println("You have been alive for "+secondslived+" seconds.");
    System.out.println("The average human life is 2,500,000,000 seconds");
    System.out.println("You have "+(averagelife - secondslived)+" seconds to live!");
    Instructions call for printf statements!

  2. #22
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default Re: Seconds Left to Live

    Quote Originally Posted by mc1234 View Post
    Instructions call for printf statements!
    Change

    Java Code:
    System.out.printf("You have been alive for %,d seconds.\n", secondslived);
    System.out.println("The average human life is 2,500,000,000 seconds");
    System.out.printf("You have " + (averagelife - secondslived) + " seconds to live!");
    to

    Java Code:
    System.out.printf("You have been alive for %d seconds.\n", secondslived);
    System.out.println("The average human life is 2,500,000,000 seconds");
    System.out.printf("You have %d seconds to live!", (averagelife - secondslived));

  3. #23
    bunty83 is offline Member
    Join Date
    Oct 2011
    Location
    North Carolina
    Posts
    5
    Rep Power
    0

    Default Re: Seconds Left to Live

    you can add comma by simply add comma between % and d.( check out one in red)

    System.out.printf("You have been alive for %,d seconds.\n", secondslived);
    System.out.println("The average human life is 2,500,000,000 seconds");
    System.out.printf("You have %,d seconds to live!", (averagelife - secondslived));

  4. #24
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default Re: Seconds Left to Live

    Quote Originally Posted by bunty83 View Post
    you can add comma by simply add comma between % and d.( check out one in red)

    System.out.printf("You have been alive for %,d seconds.\n", secondslived);
    System.out.println("The average human life is 2,500,000,000 seconds");
    System.out.printf("You have %,d seconds to live!", (averagelife - secondslived));
    That is correct.

  5. #25
    mc1234 is offline Member
    Join Date
    Sep 2011
    Posts
    24
    Rep Power
    0

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Reversing dojo slider to make it slide from right to left rather left to right as giv
    By gurpreet.singh in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-05-2011, 01:49 PM
  2. square moves left and down but not up or left
    By natdizzle in forum AWT / Swing
    Replies: 3
    Last Post: 02-04-2011, 05:20 PM
  3. Replies: 4
    Last Post: 09-09-2010, 11:15 AM
  4. how to get the seconds out of it
    By baktha.thalapathy in forum New To Java
    Replies: 15
    Last Post: 06-09-2010, 03:24 AM
  5. Replies: 3
    Last Post: 04-05-2010, 01:08 PM

Posting Permissions

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