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);
}
1
Expert's answer
2018-05-03T03:33:10-0400
Dear SHEHZAAD, your question requires a lot of work, which neither of our experts is ready to perform for free. We advise you to convert it to a fully qualified order and we will try to help you. Please click the link below to proceed: Submit order
Comments
Leave a comment