Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MultiplicationTable
- {
- private static void fillMultiplicationTable(int[][] table)
- {
- for (int i=0; i<table.length; i++)
- {
- for (int j=0; j<table[i].length; j++)
- {
- table[i][j] = (i+1) * (j+1);
- }
- }
- }
- public static void main(String[] args)
- {
- int[][] table = new int[10][10];
- fillMultiplicationTable(table);
- System.out.print(" ");
- for (int j=0; j<table[0].length; j++)
- {
- if (j < 9)
- {
- System.out.print(" ");
- }
- System.out.print(j+1);
- System.out.print(" ");
- }
- System.out.println();
- System.out.print("----");
- for (int j=0; j<table[0].length; j++)
- {
- System.out.print("---");
- }
- System.out.println();
- for (int i=0; i<table.length; i++)
- {
- if (i < 9)
- {
- System.out.print(" ");
- }
- System.out.print(i+1);
- System.out.print(" | ");
- for (int j=0; j<table[i].length; j++)
- {
- int value = table[i][j];
- if (value < 10)
- {
- System.out.print(" ");
- }
- System.out.print(value);
- System.out.print(" ");
- }
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment