TableUtilities.java 1.0KB

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