import javax.swing.JOptionPane; public class Repeat { public void whileLoop() { int num, k = 0; String input, numStr, result = ""; input = JOptionPane.showInputDialog("Repeat what?"); numStr = JOptionPane.showInputDialog("How many times"); num = Integer.parseInt(numStr); while (k < num) { result = result + input + "\n"; k++; } JOptionPane.showMessageDialog(null, result); } public void doubleTheMoney() { String amountStr = JOptionPane.showInputDialog("Initial amount? "); double amount = Double.parseDouble(amountStr); double initialAmount = amount; String rateStr = JOptionPane.showInputDialog("Interest rate? "); double rate = Double.parseDouble(rateStr); int year = 0; double interest; while (amount < 2 * initialAmount) { interest = amount * rate; amount = amount + interest; year++; System.out.println("year: " + year + "amount: " + amount); } JOptionPane.showMessageDialog(null, "amount is $" + amount + " after " + year + " years."); } public void forLoopExample() { int k; for (k = 0; k < 20; k++) System.out.println("k: " + k + "Happy Thursday"); } public void nestedLoops() { int row, col; String result = ""; for (row = 0; row < 7; row++) { for (col = 0; col <= row; col++) { result = result + "*"; } result = result + "\n"; } JOptionPane.showMessageDialog(null, result); } public static void main(String[] args) { Repeat r = new Repeat(); //r.whileLoop(); //r.doubleTheMoney(); //r.forLoopExample(); r.nestedLoops(); } }