Please add comments to my code. Thank you import javax.swing.*; /* Outputs the table to a Dialog box */ class multiplication { public static void main(String args[]) { String table = ""; String sizeStr = "Input the size of the multiplication table:"; int size; sizeStr = JOptionPane.showInputDialog(null, sizeStr); size = Integer.parseInt(sizeStr); if (size <= 0) { JOptionPane.showMessageDialog(null, "No output for value <= 0."); } else { // header table += " "; for (int i = 0; i < size; i++) { table += (i+1); table += " "; } table += "\n"; // table for (int i = 1; i <= size; i++) { for (int j = 1; j <= size; j++) { table += (i * j); table += " "; } table += "\n"; } JOptionPane.showMessageDialog(null, table); } System.exit(0); }// end main method }// end class
Please add comments to my code. Thank you
import javax.swing.*;
/* Outputs the table to a Dialog box */
class multiplication {
public static void main(String args[]) {
String table = "";
String sizeStr = "Input the size of the multiplication table:";
int size;
sizeStr = JOptionPane.showInputDialog(null, sizeStr);
size = Integer.parseInt(sizeStr);
if (size <= 0) {
JOptionPane.showMessageDialog(null, "No output for value <= 0.");
} else {
// header
table += " ";
for (int i = 0; i < size; i++) {
table += (i+1);
table += " ";
}
table += "\n";
// table
for (int i = 1; i <= size; i++) {
for (int j = 1; j <= size; j++) {
table += (i * j);
table += " ";
}
table += "\n";
}
JOptionPane.showMessageDialog(null, table);
}
System.exit(0);
}// end main method
}// end class
Step by step
Solved in 3 steps with 3 images