TableUtilities.java 1.7KB

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 myString = String.valueOf(multiply);
  8. answer = answer.concat(String.format("%3s |", myString));
  9. }
  10. answer = answer.concat("\n");
  11. }
  12. System.out.println(answer);
  13. return answer;
  14. }
  15. public static String getLargeMultiplicationTable() {
  16. String answer = "";
  17. for(int i=1; i <= 10;i++){
  18. for(int j=1; j <= 10; j++){
  19. int multiply = i * j;
  20. String myString = String.valueOf(multiply);
  21. answer = answer.concat(String.format("%3s |", myString));
  22. }
  23. answer = answer.concat("\n");
  24. }
  25. System.out.println(answer);
  26. return answer;
  27. }
  28. public static String getMultiplicationTable(int tableSize) {
  29. String answer = "";
  30. for(int i=1; i <= tableSize;i++){
  31. for(int j=1; j <= tableSize; j++){
  32. int multiply = i * j;
  33. String myString = String.valueOf(multiply);
  34. answer = answer.concat(String.format("%3s |", myString));
  35. }
  36. answer = answer.concat("\n");
  37. }
  38. System.out.println(answer);
  39. return answer;
  40. }
  41. }