Difference between revisions of "Be the Machine - if"

From Progzoo
Jump to: navigation, search
(Problem 1)
 
(26 intermediate revisions by 2 users not shown)
Line 4: Line 4:
 
public class Cia{
 
public class Cia{
 
QcQ
 
QcQ
 +
 
public static void main(String [] argv)
 
public static void main(String [] argv)
 
     throws Exception{
 
     throws Exception{
Line 12: Line 13:
 
       String [] wrds = line.split("\t");
 
       String [] wrds = line.split("\t");
 
       oneLine(wrds[0], wrds[1],Integer.parseInt(wrds[2]),
 
       oneLine(wrds[0], wrds[1],Integer.parseInt(wrds[2]),
         Long.parseLong(wrds[3]),Long.parseLong(wrds[4]));
+
         Long.parseLong(wrds[3]));
 
     }
 
     }
 
   }
 
   }
 
}
 
}
 
</shell>
 
</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);
+
     System.out.println(name);  
 
}
 
}
 
</prog>
 
</prog>
 
</question>
 
</question>
 +
 
==Problem 2==
 
==Problem 2==
 
<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 (pop > 200)
 
   if (pop > 200)
 
     System.out.println(name);
 
     System.out.println(name);
Line 41: Line 112:
 
<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 (pop == 280)
 
   if (pop == 280)
 
     System.out.println(name);
 
     System.out.println(name);
Line 51: Line 122:
 
<prog><![CDATA[
 
<prog><![CDATA[
 
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 (pop<100 && area<100)
 
   if (pop<100 && area<100)
 
     System.out.println(name);
 
     System.out.println(name);
Line 62: Line 133:
 
<prog><![CDATA[
 
<prog><![CDATA[
 
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 (pop<100 || area<100)
 
   if (pop<100 || area<100)
 
     System.out.println(name);
 
     System.out.println(name);
Line 72: Line 143:
 
<prog><![CDATA[
 
<prog><![CDATA[
 
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 (pop<100 && pop<200)
+
   if (pop>100 && pop<200)
 
     System.out.println(name);
 
     System.out.println(name);
 
}
 
}
 
]]></prog>
 
]]></prog>
 
</question>
 
</question>
 +
 
==Problem 7==
 
==Problem 7==
 
<question className="Cia" title="What's the output?" copyfile="bbc4.txt">
 
<question className="Cia" title="What's the output?" copyfile="bbc4.txt">
 
<prog><![CDATA[
 
<prog><![CDATA[
 
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 (pop<50 && pop>300)
+
   if (pop<50 || pop>300)
 
     System.out.println(name);
 
     System.out.println(name);
 
}
 
}
Line 92: Line 164:
 
<prog><![CDATA[
 
<prog><![CDATA[
 
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 (pop>area)
 
   if (pop>area)
 
     System.out.println(name);
 
     System.out.println(name);

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]