Guest User

Untitled

a guest
Jun 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. public class MultiplicationTable
  2. {
  3. private static void fillMultiplicationTable(int[][] table)
  4. {
  5. for (int i=0; i<table.length; i++)
  6. {
  7. for (int j=0; j<table[i].length; j++)
  8. {
  9. table[i][j] = (i+1) * (j+1);
  10. }
  11. }
  12. }
  13.  
  14. public static void main(String[] args)
  15. {
  16. int[][] table = new int[10][10];
  17.  
  18. fillMultiplicationTable(table);
  19.  
  20. System.out.print(" ");
  21. for (int j=0; j<table[0].length; j++)
  22. {
  23. if (j < 9)
  24. {
  25. System.out.print(" ");
  26. }
  27. System.out.print(j+1);
  28. System.out.print(" ");
  29. }
  30. System.out.println();
  31. System.out.print("----");
  32. for (int j=0; j<table[0].length; j++)
  33. {
  34. System.out.print("---");
  35. }
  36. System.out.println();
  37. for (int i=0; i<table.length; i++)
  38. {
  39. if (i < 9)
  40. {
  41. System.out.print(" ");
  42. }
  43. System.out.print(i+1);
  44. System.out.print(" | ");
  45. for (int j=0; j<table[i].length; j++)
  46. {
  47. int value = table[i][j];
  48. if (value < 10)
  49. {
  50. System.out.print(" ");
  51. }
  52. System.out.print(value);
  53. System.out.print(" ");
  54. }
  55. System.out.println();
  56. }
  57. }
Add Comment
Please, Sign In to add comment