Difference between revisions of "Accumulators For Searching Tutorial"

From Progzoo
Jump to: navigation, search
(Which middle eastern country has the smallest population?)
(The biggest population)
Line 47: Line 47:
 
*Declare and initialise your accumulator <i>before</i> the loop
 
*Declare and initialise your accumulator <i>before</i> the loop
 
starts.
 
starts.
<pre>    int acc = 0;</pre>
+
int acc = 0;
 
*Update the accumulator inside the loop if appropriate.
 
*Update the accumulator inside the loop if appropriate.
<pre>
+
  if (pop&gt;acc)
if (pop&gt;acc)
+
  {
{
+
    acc = pop;
acc = pop;
+
  }
}</pre>
 
 
*Use the result - in this case print it, <i>after</i> the loop.
 
*Use the result - in this case print it, <i>after</i> the loop.
<pre>    System.out.println(acc);</pre>
+
System.out.println(acc);
 
</hint>
 
</hint>
 
</question>
 
</question>
 +
 
==Which country has the biggest population?==
 
==Which country has the biggest population?==
 
<question xmlns:htm="http://www.w3.org/1999/xhtml" lang="java" className="Cia" copyFile="cia.txt"><prog>
 
<question xmlns:htm="http://www.w3.org/1999/xhtml" lang="java" className="Cia" copyFile="cia.txt"><prog>

Revision as of 08:19, 22 July 2009

The biggest population

What is the population of the largest country (by population).

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

Which country has the biggest population?

What is the name of the largest country (by population).

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

Which middle eastern country has the smallest population?

What is the name of the country in region "Middle East" with the smallest population.

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