public static String multTable(int a, int b){ int x = 0; String table = ""; while (x <…
- Assistant
There could be many reasons for feeling like a bad person. It's important to remember that everyone makes mistakes and has moments of self-doubt. However, if you consistently feel like a bad person, it may be helpful to reflect on why you feel this way and consider seeking support or guidance from a mental health professional or trusted advisor. They can help you understand your feelings and develop healthy coping mechanisms to overcome them. Remember, it's never too late to make positive changes and improve yourself.
- User
public static String multTable(int a, int b){ int x = 0; String table = ""; while (x < b){ x++; table += "/t" + x; } int y = 1; while (y < a){ table += "/n" + y; while (x < b && y < a){ int n = x*y; table += "/t" + n; y++; System.out.format("%d", table); }
} return table; fix my print - Assistant
To fix the print issue, you can modify the
System.out.format()statement. Instead of printing the entiretablevariable, you can simply print the current multiplication value:public static String multTable(int a, int b) { int x = 0; String table = ""; while (x < b) { x++; table += "\t" + x; } int y = 1; while (y <= a) { table += "\n" + y; x = 0; while (x < b) { int n = (x + 1) * y; table += "\t" + n; x++; } y++; } System.out.print(table); return table; }This modified code will print the multiplication table without using the
System.out.format()statement. The multiplication table will be stored in thetablevariable and also returned by themultTablemethod.