8 Copy and paste this code exactly as it is in Eclipse if yo

8. Copy and paste this code exactly as it is in Eclipse (if you have trouble doing that off of this PDF file, I’ve copied this over into a stand-alone file called “H6_q8_code.txt” in the Assignment2 tab for Homework #6). This code contains 10 errors – find them and fix them all. Some are syntactical; some are grammatical, while others are logical. Save and run the code to make sure (what do you expect the correct code to do? That should help you figure this out!) (10 pts.)

Int beerNum = 99;

String word = \"bottles\";

while (beerNum > 0) {

if (beerNum = 1) {

/ When it’s just one, it’s bottle, not bottles

word = \"bottle\" }

System.out.println(beerNum + \" \" + word + \" of beer on the wall\");

System.out.println(beerNum + \" \" + word + \" of beer\");

System.put.println(Take one down.);

System.out.println(\"Pass it around.\");

beerNum = beerNum + 1;

if (beerNum.isgreaterthan(0)) {

System.out.println(beerNum + \" \" + word + \" of beer on the wall\"); }

while {

System.out.println(\"No more bottles of beer on the wall\");

}

}

}

Solution


/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

public class MainClass {

public static void main(String[] args)
{
int beerNum = 10;
String word = \"bottles\";
  
while (beerNum > 0) {
if (beerNum == 1)
{
// When it’s just one, it’s bottle, not bottles
word = \"bottle\";
}
  
System.out.println(beerNum + \" \" + word + \" of beer on the wall\");
System.out.println(beerNum + \" \" + word + \" of beer\");
  
System.out.println(\"Take one down.\");
System.out.println(\"Pass it around.\");
  
beerNum = beerNum - 1;
if (beerNum > 0) {
//System.out.println(beerNum + \" \" + word + \" of beer on the wall\"); }
}
else {
System.out.println(\"No more bottles of beer on the wall\");
}
}
}
}

OUTPUT:

run:
10 bottles of beer on the wall
10 bottles of beer
Take one down.
Pass it around.
9 bottles of beer on the wall
9 bottles of beer
Take one down.
Pass it around.
8 bottles of beer on the wall
8 bottles of beer
Take one down.
Pass it around.
7 bottles of beer on the wall
7 bottles of beer
Take one down.
Pass it around.
6 bottles of beer on the wall
6 bottles of beer
Take one down.
Pass it around.
5 bottles of beer on the wall
5 bottles of beer
Take one down.
Pass it around.
4 bottles of beer on the wall
4 bottles of beer
Take one down.
Pass it around.
3 bottles of beer on the wall
3 bottles of beer
Take one down.
Pass it around.
2 bottles of beer on the wall
2 bottles of beer
Take one down.
Pass it around.
1 bottle of beer on the wall
1 bottle of beer
Take one down.
Pass it around.
No more bottles of beer on the wall
BUILD SUCCESSFUL (total time: 0 seconds)

8. Copy and paste this code exactly as it is in Eclipse (if you have trouble doing that off of this PDF file, I’ve copied this over into a stand-alone file call
8. Copy and paste this code exactly as it is in Eclipse (if you have trouble doing that off of this PDF file, I’ve copied this over into a stand-alone file call
8. Copy and paste this code exactly as it is in Eclipse (if you have trouble doing that off of this PDF file, I’ve copied this over into a stand-alone file call

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site