0

How can I align it properly?
got hard time. sorry i'm just new in Java

public class MultiplicationTable {
    public static void main(String[] args) {
       
        int[][] multtable = new int[11][11];


        System.out.print("*");
        for (int a=1;a<=10;a++)
        {
            System.out.print("\t"+a) ;
        }
        System.out.println(" ");
        for(int i=0; i<=10; i++) {           // this loop is for rows
            for(int j=0; j<=10; j++) {       // this loop is for columns
                multtable[i][j] = i*j;
            }
        }
        System.out.print("\t");
        System.out.print("------------------------------------------------------------------");
        System.out.println("");

        for(int i=1; i<11; i++) {
            System.out.print(i+"|\t");

            for(int j=1; j<11; j++) {
                // this ensures that all single-digit numbers will line up into columns
                System.out.print(multtable[i][j]+"\t");
            }
            // make a new line for every row
           System.out.print("\n");
        }
    }
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by masijade
0

See the "printf" method of PrintWriter, or the format method of String in the API docs, then simply format the print so each number (with leading/separating/trailing whitespace) uses the same number of characters.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.