TableUtilities.java 1.1KB

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