# Difference between revisions of "Java Test 1"

Line 184: | Line 184: | ||

} | } | ||

--> | --> | ||

− | <div class="i" data-regex="^\s* | + | <div class="i" data-regex="^\s*5\s*$" data-regex_flags="g"></div> |

</div> | </div> |

## Revision as of 16:17, 17 July 2015

State the output from this program fragment:

```
int a = 5;
int b = 7;
a = a + b;
b = a + b;
System.out.println(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");}
``` |
---|---|

Output | xxxx |

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");}
``` |
---|---|

Output | xxx |

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

Program Fragment |
```
int i = 0;<br />
while (i++<q) {System.out.print("x");}
``` |
---|---|

Output | xx |

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 x is defined by

```
int x[] = {1,3,0,2};
```

The array y is such that `y[x[i]] == i`

for all values of i from 0 to 3

```
Evaluate y[0]+y[2]
```