Difference between revisions of "Be the Machine - if"

From Progzoo
Jump to: navigation, search
(Problem 1)
 
(16 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;">
 
<table align="right" border="1" cellpadding="2" style="border-collapse:collapse;">
 
   <tr style="font-weight:bold;">
 
   <tr style="font-weight:bold;">
Line 27: Line 29:
 
     <td>Chad</td>
 
     <td>Chad</td>
 
     <td>Africa</td>
 
     <td>Africa</td>
     <td>1280</td>
+
     <td style='text-align:right'>1280</td>
     <td>91</td>
+
     <td style='text-align:right'>9</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
 
     <td>Cuba</td>
 
     <td>Cuba</td>
 
     <td>Americas</td>
 
     <td>Americas</td>
     <td>110</td>
+
     <td style='text-align:right'>111</td>
     <td>113</td>
+
     <td style='text-align:right'>11</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
 
     <td>Fiji</td>
 
     <td>Fiji</td>
 
     <td>Asia-Pacific</td>
 
     <td>Asia-Pacific</td>
     <td>18</td>
+
     <td style='text-align:right'>18</td>
     <td>8</td>
+
     <td style='text-align:right'>1</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
 
     <td>Iran</td>
 
     <td>Iran</td>
 
     <td>Middle East</td>
 
     <td>Middle East</td>
     <td>1650</td>
+
     <td style='text-align:right'>1650</td>
     <td>707</td>
+
     <td style='text-align:right'>71</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
 
     <td>Iraq</td>
 
     <td>Iraq</td>
 
     <td>Middle East</td>
 
     <td>Middle East</td>
     <td>438</td>
+
     <td style='text-align:right'>438</td>
     <td>265</td>
+
     <td style='text-align:right'>27</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
 
     <td>Laos</td>
 
     <td>Laos</td>
 
     <td>Asia-Pacific</td>
 
     <td>Asia-Pacific</td>
     <td>236</td>
+
     <td style='text-align:right'>238</td>
     <td>59</td>
+
     <td style='text-align:right'>6</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
 
     <td>Mali</td>
 
     <td>Mali</td>
 
     <td>Africa</td>
 
     <td>Africa</td>
     <td>1250</td>
+
     <td style='text-align:right'>1250</td>
     <td>138</td>
+
     <td style='text-align:right'>14</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
 
     <td>Oman</td>
 
     <td>Oman</td>
 
     <td>Middle East</td>
 
     <td>Middle East</td>
     <td>309</td>
+
     <td style='text-align:right'>310</td>
     <td>30</td>
+
     <td style='text-align:right'>3</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
 
     <td>Peru</td>
 
     <td>Peru</td>
 
     <td>South America</td>
 
     <td>South America</td>
     <td>1280</td>
+
     <td style='text-align:right'>1280</td>
     <td>280</td>
+
     <td style='text-align:right'>28</td>
 
   </tr>
 
   </tr>
 
   <tr>
 
   <tr>
 
     <td>Togo</td>
 
     <td>Togo</td>
 
     <td>Africa</td>
 
     <td>Africa</td>
     <td>56</td>
+
     <td style='text-align:right'>57</td>
     <td>51</td>
+
     <td style='text-align:right'>5</td>
 
   </tr>
 
   </tr>
 
</table>
 
</table>
Line 89: Line 91:
 
<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 109: 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 119: 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 130: 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 140: 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);
Line 151: Line 154:
 
<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 161: 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]