Computer Science › Unit Testing
Consider the Array
int[] arr = {1, 2, 3, 4, 5};
What are the values in arr
after the following code is executed?
for (int i = 0; i < arr.length - 2; i++)
{
int temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp;
}
The function fun
is defined as follows:
public int fun(int[] a)
{
a[a.length - 1] = a[0];
return a[0] + (a[0] % 2);
}
What is the value of a[0]
after the following code segment is executed?
int[] a = {3, 6, 9, 12};
a[0] = fun(a);
What are the values of x
, y
, and z
after the following code is executed?
int x = 4, y = 3, z;
for (int i = 0; i < 5; i++)
{
z = x + y;
y = x - y;
x = z;
}
Consider the method
public String mystery(String s)
{
String s1 = s.substring(0,1);
String s2 = s.substring(1,2);
String s3 = s.substring(2, s.length() - 2);
String s4 = s.substring(s.length() - 2, s.length() - 1);
String s5 = s.substring(s.length() - 1);
if (s.length() <= 5)
return s5 + s4 + s3 + s2 + s1;
else
return s1 + s2 + mystery(s3) + s4 + s5;
}
What is the output of
System.out.println(mystery("ABNORMALITIES"));