Results 1 to 5 of 5
  1. #1
    Xavier is offline Member
    Join Date
    May 2013
    Posts
    7
    Rep Power
    0

    Default Transfering .format to .println statements PLEASE HELP

    I have code that works but i need to transfer system.out.format statements to system.out.println statements. I am new ot this stuff so please help me out and as soon as possible.

    import java.util.Scanner;

    public class MultiplicationTable {
    public static void main(String[] args) {
    int tableSize = 0;
    Scanner scan = new Scanner(System.in);
    System.out.println("Enter number of columns: ");
    tableSize = scan.nextInt();
    for(int i = 1; i<=tableSize;i++ ) {
    System.out.format(" %4d ",i);}
    System.out.println();
    for(int i = 1 ;i<=tableSize;i++) {
    System.out.format("%4d ",i);
    for(int j=1;j<=tableSize;j++) {
    System.out.format("%4d",i*j);
    }
    System.out.println();
    }
    }
    }

  2. #2
    jbarke12's Avatar
    jbarke12 is offline Member
    Join Date
    May 2013
    Location
    Charleston, South Carolina USA
    Posts
    88
    Rep Power
    0

    Default Re: Transfering .format to .println statements PLEASE HELP

    I would do
    Java Code:
    System.out.println(String.format(" %4d ",i));

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default Re: Transfering .format to .println statements PLEASE HELP

    Quote Originally Posted by Xavier View Post
    I have code that works but i need to transfer system.out.format statements to system.out.println statements. I am new ot this stuff so please help me out and as soon as possible.
    Why? You can change 'format' to 'printf' without any trouble but it's beyond me why you should want to change it to 'println' ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    2

    Default Re: Transfering .format to .println statements PLEASE HELP

    why? just specify in the format statements you want a new line, that will do the same job.

  5. #5
    jbarke12's Avatar
    jbarke12 is offline Member
    Join Date
    May 2013
    Location
    Charleston, South Carolina USA
    Posts
    88
    Rep Power
    0

    Default Re: Transfering .format to .println statements PLEASE HELP

    Quote Originally Posted by monkeyjr97 View Post
    why? just specify in the format statements you want a new line, that will do the same job.
    This is the better way to do it. I just showing you the code snippet for what you were asking for.

Similar Threads

  1. How do you format to two decimal places with println()?
    By EscSequenceAlpha in forum New To Java
    Replies: 4
    Last Post: 04-05-2012, 08:27 PM
  2. Replies: 0
    Last Post: 02-09-2012, 09:25 AM
  3. Println VS system.out.println
    By ccie007 in forum New To Java
    Replies: 2
    Last Post: 05-20-2010, 08:52 AM
  4. Loop System print or println statements
    By Singing Boyo in forum New To Java
    Replies: 6
    Last Post: 03-22-2009, 03:52 AM
  5. difference between system.out.println() & out.println()
    By wickedrahul9 in forum Advanced Java
    Replies: 5
    Last Post: 10-18-2008, 11:06 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
  •