473,394 Members | 1,965 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Writing a Java application called Bottle.java

3
Hi Guys.

I have to write and display the following song using an appropriate loop.

10 green bottles
Hanging on the wall
And if 1 green bottle
Should accidentally fall
There'll be 9 green bottles
Hanging on the wall

9 green bottles
Hanging on the wall
And if 1 green bottle
Should accidentally fall
There'll be 8 green bottles
Hanging on the wall green

. . . . . . . . .

. . . . . . . . .

1 green bottle
Hanging on the wall
And if 1 green bottle
Should accidentally fall
There'll be 0 green bottles
Hanging on the wall.



This is my attempt to the solution, but it does not compile

public class Bottle {
public static void main (String[] args) {

int x = 10;
System.out.println(x "\n green bottles ");
while ( x >= 1 ) {
for (int i = 0; i < 10; i++) {
System.out.println(" Hanging on the wall ");
System.out.println(" And if 1 green bottle ");
System.out.println(" Should accidentally break ");
System.out.println(" There'll be " x - 1 " green bottles ");
System.out.println(" Hanging on the wall \n" );

System.out.println("\n x - 1 green bottles ");
}
}
}
Feb 15 '07 #1
1 1230
r035198x
13,262 8TB
Hi Guys.

I have to write and display the following song using an appropriate loop.

10 green bottles
Hanging on the wall
And if 1 green bottle
Should accidentally fall
There'll be 9 green bottles
Hanging on the wall

9 green bottles
Hanging on the wall
And if 1 green bottle
Should accidentally fall
There'll be 8 green bottles
Hanging on the wall green

. . . . . . . . .

. . . . . . . . .

1 green bottle
Hanging on the wall
And if 1 green bottle
Should accidentally fall
There'll be 0 green bottles
Hanging on the wall.



This is my attempt to the solution, but it does not compile

public class Bottle {
public static void main (String[] args) {

int x = 10;
System.out.println(x "\n green bottles ");
while ( x >= 1 ) {
for (int i = 0; i < 10; i++) {
System.out.println(" Hanging on the wall ");
System.out.println(" And if 1 green bottle ");
System.out.println(" Should accidentally break ");
System.out.println(" There'll be " x - 1 " green bottles ");
System.out.println(" Hanging on the wall \n" );

System.out.println("\n x - 1 green bottles ");
}
}
}
To concatenate a variable with a string constant eg, to append "world" to the variable x you write
x+"world". i.e You use the + operator to concatenate wth strings. Fix that in your code and post if you get any other problems.
Feb 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the...
6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
385
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like...
1
by: Robert Strickland | last post by:
We are developing a several web applications that use 'services' that perform key business functions for our applications. These same 'services' are avaible to paying clients through web services. ...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
5
by: Radesh | last post by:
Hi Guys. I have to write and display the following song using an appropriate loop. 10 green bottles Hanging on the wall And if 1 green bottle Should accidentally fall There'll be 9 green...
5
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.