Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Rewrite the java program below so that it uses a For loop instead of a While loo

ID: 3621058 • Letter: R

Question

Rewrite the java program below so that it uses a For loop instead of a While loop. Note that For loops count up while the song counts down.

// Variables
var count; // numeric

// Main Program
count = parseFloat(prompt(“How many bottles?”,0));
while ((count > 0))
{
document.write(count);
document.writeln(“ bottles of beer on the wall,”);
document.write(count);
document.writeln((“ bottles of beer,”);
document.write(“take one down. pass it around);
count = count - 1
document.write(count);
document.writeln(“ bottles of beer on the wall,”);
document.writeln(“ “);
}

The output reads:

1.0 bottles of beer on the wall,
1.0 bottles of beer.
Take one down. Pass it around.
0.0 bottles of beer on the wall.

Explanation / Answer

please rate -thanks

loops can count down, so I've done the solution 2 ways

// Variables
var count; // numeric
int i;
// Main Program
count = parseFloat(prompt(“How many bottles?”,0));
for(
{i=count;i>=1;i--)
document.write(count);
document.writeln(“ bottles of beer on the wall,”);
document.write(count);
document.writeln((“ bottles of beer,”);
document.write(“take one down. pass it around);

}

document.write(i);
document.writeln(“ bottles of beer on the wall,”);
document.writeln(“ “);

-------------------------------------------------------------------------

// Variables
var count; // numeric
int i, max=count;
// Main Program
count = parseFloat(prompt(“How many bottles?”,0));
for(i=0;i<max;i++)
{count=max-i;
document.write(count);
document.writeln(“ bottles of beer on the wall,”);
document.write(count);
document.writeln((“ bottles of beer,”);
document.write(“take one down. pass it around);
}
document.write(i);
document.writeln(“ bottles of beer on the wall,”);
document.writeln(“ “);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote