TableUtilities.java 1.3KB

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