Question 11
public class First { public static int CBSE (int x) { if (x < 100) x = CBSE (x + 10); return (x – 1); } public static void main (String[] args){ System.out.print(First.CBSE(60)); } }What does this program print ?
Question 12
The function f is defined as follows:
int f (int n) {
if (n <= 1) return 1;
else if (n % 2 == 0) return f(n/2);
else return f(3n - 1);
}
Assuming that arbitrarily large integers can be passed as a parameter to the function, consider the following statements.
1. The function f terminates for finitely many different values of n ≥ 1.
ii. The function f terminates for infinitely many different values of n ≥ 1.
iii. The function f does not terminate for finitely many different values of n ≥ 1.
iv. The function f does not terminate for infinitely many different values of n ≥ 1.
Which one of the following options is true of the above?
Question 13
Study the following program:
// precondition: x>=0 public void demo(int x) { System.out.print(x % 10); if (x % 10 != 0) { demo(x / 10); } System.out.print(x % 10); }
Which of the following is printed as a result of the call demo(1234)?
Question 14
1 public class While 2 { 3 public void loop() 4 { 5 int x = 0; 6 while(1) 7 { 8 System.out.println("x plus one is" +(x+1)); 9 } 10 } 11 }
Question 15
program side-effect (input, output); var x, result: integer; function f (var x:integer):integer; begin x:x+1;f:=x; end; begin x:=5; result:=f(x)*f(x); writeln(result); end;
Question 16
class Test
{
public void demo(String str)
{
String[] arr = str.split(\";\");
for (String s : arr)
{
System.out.println(s);
}
}
public static void main(String[] args)
{
char array[] = {\'a\', \'b\', \' \', \'c\', \'d\', \';\', \'e\', \'f\', \' \',
\'g\', \'h\', \';\', \'i\', \'j\', \' \', \'k\', \'l\'};
String str = new String(array);
Test obj = new Test();
obj.demo(str);
}
}
Question 17
class Test {
public static void swap(Integer i, Integer j) {
Integer temp = new Integer(i);
i = j;
j = temp;
}
public static void main(String[] args) {
Integer i = new Integer(10);
Integer j = new Integer(20);
swap(i, j);
System.out.println(\"i = \" + i + \", j = \" + j);
}
}
There are 17 questions to complete.