1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. public class TableUtilities {
  2. public static String getSmallMultiplicationTable() {
  3. //StringBuilder sb = new StringBuilder();
  4. String str="";
  5. int product = 0;
  6. for(int i=1;i<=5;i++)
  7. {
  8. for(int j=1; j<=5;j++)
  9. {
  10. product=i*j;
  11. str +=String.format("%3d |",product);
  12. }
  13. str +="\n";
  14. }
  15. return str;
  16. }
  17. public static String getLargeMultiplicationTable() {
  18. //StringBuilder sb = new StringBuilder();
  19. String str="";
  20. int product = 0;
  21. for(int i=1;i<=10;i++)
  22. {
  23. for(int j=1; j<=10;j++)
  24. {
  25. //sb.append(" ");
  26. product =i*j;
  27. str +=String.format("%3d |",product);
  28. } str +="\n";
  29. }
  30. return str;
  31. }
  32. public static String getMultiplicationTable(int tableSize) {
  33. /*StringBuilder str = new StringBuilder();
  34. int product = 0;
  35. for(int i=1;i<=tableSize;i++)
  36. {
  37. for(int j=1; j<=tableSize;j++)
  38. {
  39. product =i*j;
  40. str +=String.format("%3d |",product);
  41. } str +="\n";
  42. System.out.println ("Final triangle String for input - " + " \n " + sb.toString());
  43. return str;*/
  44. String str="";
  45. int product=0;
  46. for(int i=1;i<=tableSize;i++)
  47. {
  48. for(int j=1; j<=tableSize;j++)
  49. {
  50. product=i*j;
  51. str +=String.format("%3d |",product);
  52. } str +="\n";
  53. }return str;
  54. }
  55. }