TableUtilities.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. public class TableUtilities {
  2. public static String getSmallMultiplicationTable()
  3. {
  4. String str= "";
  5. for (int i=1; i<=5; i++)
  6. {
  7. int result=0;
  8. for(int j=1; j<=5; j++)
  9. {
  10. result = i*j;
  11. str += String.format("%3d |",result);
  12. }
  13. str += "\n";
  14. }
  15. return str;
  16. }
  17. public static String getLargeMultiplicationTable() {
  18. String str= "";
  19. for (int i=1; i<=10; i++)
  20. {
  21. int result=0;
  22. for(int j=1; j<=10; j++)
  23. {
  24. result = i*j;
  25. str += String.format("%3d |",result);
  26. }
  27. str += "\n";
  28. }
  29. return str;
  30. }
  31. public static String getMultiplicationTable(int tableSize) {
  32. String str= "";
  33. for (int i=1; i<=tableSize; i++)
  34. {
  35. int result=0;
  36. for(int j=1; j<=tableSize; j++)
  37. {
  38. result = i*j;
  39. str += String.format("%3d |",result);
  40. }
  41. str += "\n";
  42. }
  43. return str;
  44. }
  45. }