Difference between revisions of "Java Test 1"

From Progzoo
Jump to: navigation, search
(Created page with "<div class='quiz'> <div class='q'> State the output from this program fragment:<br/> <syntaxhighlight lang="java"> int a = 5; int b = 7; a = a + b; b = a + b;...")
 
Line 39: Line 39:
 
<td>
 
<td>
 
for(int i=q; i<9; i+=3)<br/>
 
for(int i=q; i<9; i+=3)<br/>
&nbsp;&nbsp;System.out.print("x");
+
  System.out.print("x");
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 53: Line 53:
 
<td>
 
<td>
 
for(int i=q; i<9; i+=3)<br/>
 
for(int i=q; i<9; i+=3)<br/>
&nbsp;&nbsp;System.out.print("x");
+
  System.out.print("x");
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 68: Line 68:
 
int i = 0;<br />
 
int i = 0;<br />
 
while (i++<q)
 
while (i++<q)
&nbsp;&nbsp;System.out.print("x");
+
  System.out.print("x");
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 153: Line 153:
 
int b = 0;
 
int b = 0;
 
for (int i=0;i<161;i++)
 
for (int i=0;i<161;i++)
&nbsp;&nbsp;b = x[b];
+
  b = x[b];
 
System.out.println(b);
 
System.out.println(b);
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 176: Line 176:
 
}  
 
}  
 
-->
 
-->
<div class="i" data-regex="^\s*2\s*$" data-regex_flags="g"></div>
+
<div class="i" data-regex="^\s*1\s*$" data-regex_flags="g"></div>
 
</div>
 
</div>

Revision as of 15:02, 27 June 2015

State the output from this program fragment:
    int a = 5;
    int b = 7;
    a = a + b;
    b = a + b;
State the output from this program fragment:
    int a = 5;
    int b = 7;
    int c = 8;
    a = b;
    b = c;
    c = a;
    System.out.println(100*a+10*b+c)
State the output from this program fragment:
    String s = "Fourty two";
    String t = s.substring(7,8)+substring(1,4);
    System.out.println(t);
The program fragment and the output are shown. State the missing value for q
Program Fragment

for(int i=q; i<9; i+=3)

 System.out.print("x");
Outputxxxx

The program fragment and the output are shown. State the highest possible value for q.
Program Fragment

for(int i=q; i<9; i+=3)

 System.out.print("x");
Outputxxx

The program fragment and the output are shown. State the highest possible value for q.
Program Fragment

int i = 0;
while (i++<q)

 System.out.print("x");
Outputxx

Evaluate
15-5*2
Evaluate
(1+3)*(4-2)
Evaluate
int i = 7+2*3-6/4
Evaluate
The ternary expression B ? X : Y gives X if B is true and Y if B is false.
1>3?6:8
Evaluate
(2<3||6>7)?(1==1?3:4):5
Evaluate
(0==1?2>3:4>5)?6:7
Evaluate
0==1?2>3:4<5?6:7
Evaluate
The binary operator << is bit-shift-let. The expression A << B evaluates to A*2^B
((1<<3)+1)<<2
Evaluate
(123<<7)/((123<<3)<<3)
Evaluate
(123<<7)/((1<<3)<<3)
The array a is defined as:
int a[] = {4,2,8,6,9,1,3,0,7,5};
Evaluate
a[2]+1
Evaluate
a[a[3]]
Evaluate
a[a[a[a[0]]]]
Give the output of the following program fragment:
int x[] = {1,3,0,2};
int b = 0;
for (int i=0;i<161;i++)
  b = x[b];
System.out.println(b);
The array y is such that y[x[i]] == i for all values of i from 0 to 3
Evaluate y[0]+y[2]