TableUtilities.java 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. }