Difference between revisions of "Be the Machine - if"

From Progzoo
Jump to: navigation, search
(Problem 1)
(Problem 1)
 
(34 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
<shell lang="java" className="Cia" lang='java'>
 +
import java.io.BufferedReader;
 +
import java.io.FileReader;
 +
public class Cia{
 +
QcQ
  
<shell lang="java" className="Cia" import="shells_bbc.xml#fun" lang='java'/>
+
public static void main(String [] argv)
 +
    throws Exception{
 +
    BufferedReader fh =
 +
    new BufferedReader(new FileReader("bbc4.txt"));
 +
    String line;
 +
    while ((line=fh.readLine())!=null){
 +
      String [] wrds = line.split("\t");
 +
      oneLine(wrds[0], wrds[1],Integer.parseInt(wrds[2]),
 +
        Long.parseLong(wrds[3])); 
 +
    }
 +
  }
 +
}
 +
</shell>
 +
Predict the output of each of the following programs.
 +
<table align="right" border="1" cellpadding="2" style="border-collapse:collapse;">
 +
  <tr style="font-weight:bold;">
 +
    <td>name</td>
 +
    <td>region</td>
 +
    <td>area</td>
 +
    <td>pop</td>
 +
  </tr>
 +
  <tr>
 +
    <td>Chad</td>
 +
    <td>Africa</td>
 +
    <td style='text-align:right'>1280</td>
 +
    <td style='text-align:right'>9</td>
 +
  </tr>
 +
  <tr>
 +
    <td>Cuba</td>
 +
    <td>Americas</td>
 +
    <td style='text-align:right'>111</td>
 +
    <td style='text-align:right'>11</td>
 +
  </tr>
 +
  <tr>
 +
    <td>Fiji</td>
 +
    <td>Asia-Pacific</td>
 +
    <td style='text-align:right'>18</td>
 +
    <td style='text-align:right'>1</td>
 +
  </tr>
 +
  <tr>
 +
    <td>Iran</td>
 +
    <td>Middle East</td>
 +
    <td style='text-align:right'>1650</td>
 +
    <td style='text-align:right'>71</td>
 +
  </tr>
 +
  <tr>
 +
    <td>Iraq</td>
 +
    <td>Middle East</td>
 +
    <td style='text-align:right'>438</td>
 +
    <td style='text-align:right'>27</td>
 +
  </tr>
 +
  <tr>
 +
    <td>Laos</td>
 +
    <td>Asia-Pacific</td>
 +
    <td style='text-align:right'>238</td>
 +
    <td style='text-align:right'>6</td>
 +
  </tr>
 +
  <tr>
 +
    <td>Mali</td>
 +
    <td>Africa</td>
 +
    <td style='text-align:right'>1250</td>
 +
    <td style='text-align:right'>14</td>
 +
  </tr>
 +
  <tr>
 +
    <td>Oman</td>
 +
    <td>Middle East</td>
 +
    <td style='text-align:right'>310</td>
 +
    <td style='text-align:right'>3</td>
 +
  </tr>
 +
  <tr>
 +
    <td>Peru</td>
 +
    <td>South America</td>
 +
    <td style='text-align:right'>1280</td>
 +
    <td style='text-align:right'>28</td>
 +
  </tr>
 +
  <tr>
 +
    <td>Togo</td>
 +
    <td>Africa</td>
 +
    <td style='text-align:right'>57</td>
 +
    <td style='text-align:right'>5</td>
 +
  </tr>
 +
</table>
 
==Problem 1==
 
==Problem 1==
<question className="Cia" title="What's the output/" copyfile="bbc4.txt">
+
<question className="Cia" title="What's the output?" copyfile="bbc4.txt">
 
<prog>
 
<prog>
 
static void oneLine(String name, String region,
 
static void oneLine(String name, String region,
               int area, long pop, long gdp){
+
               int area, long pop){
 
   if (region.equals("Africa"))
 
   if (region.equals("Africa"))
 +
    System.out.println(name);
 +
}
 +
</prog>
 +
</question>
 +
 +
==Problem 2==
 +
<question className="Cia" title="What's the output?" copyfile="bbc4.txt">
 +
<prog>
 +
static void oneLine(String name, String region,
 +
              int area, long pop){
 +
  if (pop > 200)
 
     System.out.println(name);
 
     System.out.println(name);
 
}
 
}
 
</prog>
 
</prog>
 +
</question>
 +
==Problem 3==
 +
<question className="Cia" title="What's the output?" copyfile="bbc4.txt">
 +
<prog>
 +
static void oneLine(String name, String region,
 +
              int area, long pop){
 +
  if (pop == 280)
 +
    System.out.println(name);
 +
}
 +
</prog>
 +
</question>
 +
==Problem 4==
 +
<question className="Cia" title="What's the output?" copyfile="bbc4.txt">
 +
<prog><![CDATA[
 +
static void oneLine(String name, String region,
 +
              int area, long pop){
 +
  if (pop<100 && area<100)
 +
    System.out.println(name);
 +
}
 +
]]></prog>
 +
</question>
 +
 +
==Problem 5==
 +
<question className="Cia" title="What's the output?" copyfile="bbc4.txt">
 +
<prog><![CDATA[
 +
static void oneLine(String name, String region,
 +
              int area, long pop){
 +
  if (pop<100 || area<100)
 +
    System.out.println(name);
 +
}
 +
]]></prog>
 +
</question>
 +
==Problem 6==
 +
<question className="Cia" title="What's the output?" copyfile="bbc4.txt">
 +
<prog><![CDATA[
 +
static void oneLine(String name, String region,
 +
              int area, long pop){
 +
  if (pop>100 && pop<200)
 +
    System.out.println(name);
 +
}
 +
]]></prog>
 +
</question>
 +
 +
==Problem 7==
 +
<question className="Cia" title="What's the output?" copyfile="bbc4.txt">
 +
<prog><![CDATA[
 +
static void oneLine(String name, String region,
 +
              int area, long pop){
 +
  if (pop<50 || pop>300)
 +
    System.out.println(name);
 +
}
 +
]]></prog>
 +
</question>
 +
==Problem 8==
 +
<question className="Cia" title="What's the output?" copyfile="bbc4.txt">
 +
<prog><![CDATA[
 +
static void oneLine(String name, String region,
 +
              int area, long pop){
 +
  if (pop>area)
 +
    System.out.println(name);
 +
}
 +
]]></prog>
 
</question>
 
</question>

Latest revision as of 10:32, 15 July 2010

Predict the output of each of the following programs.

name region area pop
Chad Africa 1280 9
Cuba Americas 111 11
Fiji Asia-Pacific 18 1
Iran Middle East 1650 71
Iraq Middle East 438 27
Laos Asia-Pacific 238 6
Mali Africa 1250 14
Oman Middle East 310 3
Peru South America 1280 28
Togo Africa 57 5

Problem 1


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

Problem 2


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

Problem 3


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

Problem 4


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

Problem 5


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

Problem 6


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

Problem 7


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

Problem 8


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