TableUtilities.java 1.2KB

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