Menu

[solved] – Question 76879

Modify the following method to use a for loop instead of the while loop:
public static void sumTo()
{
int n; int total = 0; int count = 0;
String output = “”;
String str;
str = JOptionPane.showInputDialog(“Give me a number to sum to: “);
n = Integer.parseInt(str);
while (count ,= n)
{
total = total + count;
output += count +”:t” + total + “n”;
count = count + 1;
}
JOptionPane.showMessageDialog(null, output);
}

Expert Answer


OR


Leave a Reply

Your email address will not be published. Required fields are marked *