TableUtilities.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. public class TableUtilities {
  2. public static String getSmallMultiplicationTable() {
  3. //NESTED FOR LOOPS
  4. //return String.format(" %1$2d | %2$2d |", 5, 10);
  5. int outputInt = 0;
  6. String output = "";
  7. for(int i = 1; i <= 5; i++){
  8. for(int j = 1; j <= 5; j++){
  9. outputInt = i * j;
  10. //output = output + Integer.toString(outputInt) + "|";
  11. output = String.format("%1$s%2$3d |", output, outputInt);
  12. }
  13. output = output + "\n";
  14. }
  15. return output;
  16. }
  17. public static String getLargeMultiplicationTable() {
  18. int outputInt = 0;
  19. String output = "";
  20. for(int i = 1; i <= 10; i++){
  21. for(int j = 1; j <= 10; j++){
  22. outputInt = i * j;
  23. //output = output + Integer.toString(outputInt) + "|";
  24. output = String.format("%1$s%2$3d |", output, outputInt);
  25. }
  26. output = output + "\n";
  27. }
  28. return output;
  29. }
  30. public static String getMultiplicationTable(int tableSize) {
  31. int outputInt = 0;
  32. String output = "";
  33. for(int i = 1; i <= tableSize; i++){
  34. for(int j = 1; j <= tableSize; j++){
  35. outputInt = i * j;
  36. //output = output + Integer.toString(outputInt) + "|";
  37. output = String.format("%1$s%2$3d |", output, outputInt);
  38. }
  39. output = output + "\n";
  40. }
  41. return output;
  42. }
  43. }