473,769 Members | 5,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing a Java application called Bottle.java

3 New Member
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.prin tln(x "\n green bottles ");
while ( x >= 1 ) {
for (int i = 0; i < 10; i++) {
System.out.prin tln(" Hanging on the wall ");
System.out.prin tln(" And if 1 green bottle ");
System.out.prin tln(" Should accidentally break ");
System.out.prin tln(" There'll be " x - 1 " green bottles ");
System.out.prin tln(" Hanging on the wall \n" );

System.out.prin tln("\n x - 1 green bottles ");
}
}
}
Feb 15 '07 #1
1 1245
r035198x
13,262 MVP
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.prin tln(x "\n green bottles ");
while ( x >= 1 ) {
for (int i = 0; i < 10; i++) {
System.out.prin tln(" Hanging on the wall ");
System.out.prin tln(" And if 1 green bottle ");
System.out.prin tln(" Should accidentally break ");
System.out.prin tln(" There'll be " x - 1 " green bottles ");
System.out.prin tln(" Hanging on the wall \n" );

System.out.prin tln("\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
9094
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 same port to change the direction of the robot. The trajectory frame is managed by an applet, and the project works good when the applet is called by a html document allocated in the same local machine under W98 where the classes and the serial port...
6
23603
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
17303
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 extraneous jargons, such as in the Unix & Perl community. Unlike mathematicians, where in mathematics there are no fewer jargons but each and every one are
1
1250
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. To summarize, we have clients that use our web applications (they need UI) and we have clients that just need the 'services' where they integrate our 'services' with their applications through the web services. We have a single server that houses...
1
9651
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 and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
2
6966
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 attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
5
1287
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 bottles Hanging on the wall
5
6292
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 JDK 6 downloadable from http://java.sun.com/javase/downloads/index.jsp. I will be using JDK 5(update 8)
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10222
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.