Difference between revisions of "Ruby:Simple Printing Tutorial"

From Progzoo
Jump to: navigation, search
(What are the regions?)
(What are the regions?)
Line 15: Line 15:
 
</p>
 
</p>
 
<prog>
 
<prog>
def oneLine(name, region,area,pop,gdp){
+
def oneLine(name, region,area,pop,gdp)
 
   puts region
 
   puts region
 
end
 
end
 
</prog>
 
</prog>
 
<answer>
 
<answer>
def oneLine(name, region,area,pop,gdp){
+
def oneLine(name, region,area,pop,gdp)
 
   puts name
 
   puts name
 
end
 
end

Revision as of 14:53, 15 April 2008

What are the regions?

The method oneLine will get called over 200 times. Each time the five parameters

 name region area pop gdp
will have different values.

The example program lists the region for each country.

Change the program so that it prints the name instead.


[Font] [Default] [Show] [Resize] [History] [Profile]

Show the name and the population

This program prints the name and the area for each country. Notice that the +" "+ puts a space between the two variables.

Change the program so that it prints the name followed by the population instead of the area.



[Font] [Default] [Show] [Resize] [History] [Profile]

Show the population in millions

Show the name and the population in millions.


[Font] [Default] [Show] [Resize] [History] [Profile]