WorksheetsQuiz 5
Total questions: 20
Worksheet time: 10mins
int[] a = {1, 2, 3, 4};
for(int i = 0; i < a.length; i++) {
a[i] = a[(a.length - 1) - i];
}
System.out.print(a[1]);
2
3
1
4
int[] a = {5, 10, 15};
int sum = 0;
for(int i = 0; i < a.length; i++) {
sum += a[i] / a[0];
}
System.out.print(sum);
6
7
8
30
int[] a = {1, 2, 3, 4, 5};
for(int i = 1; i < a.length; i++) {
a[i] = a[i] + a[i-1];
}
System.out.print(a[3]);
8
9
10
11
int[] a = {2, 4, 6};
for(int i = 0; i < a.length; i++) {
a[i] = a[i] * i;
}
System.out.print(a[2]);
0
4
6
12
int[][] a = {
{1, 2, 3},
{4, 5, 6}
};
System.out.print(a.length + a[0].length);
3
4
5
6
int[][] a = {
{2, 4},
{6, 8}
};
for(int i = 0; i < a.length; i++) {
for(int j = 0; j < a[i].length; j++) {
if(a[i][j] % 4 == 0)
a[i][j] /= 2;
}
}
System.out.print(a[1][1]);
4
8
6
2
int[] a = {2, 4, 6, 8};
int x = a[0];
for(int i = 1; i < a.length; i++) {
x = x + a[i] - i;
}
System.out.print(x);
13
14
15
16
String s = "abcde";
System.out.print(s.substring(1,4));
bcde
bcd
abcd
abc
String s = "A" + 10 + 20;
System.out.print(s);
A30
A1020
A2030
Compilation error
String s = "java";
s = s.replace('a', 'o');
System.out.print(s);
jovo
jova
java
jav
String s = "abcd";
s.replace("ab", "xy");
System.out.print(s.substring(1, 3));
xy
yc
bc
abxy
String s = "abc";
System.out.print(s.equals(s.toUpperCase().toLowerCase()));
true
false
error
ABCabc
static void fun(String s) {
s = s + "X";
}
public static void main(String[] args) {
String s = "A";
fun(s);
s += "Y";
System.out.print(s);
}
AX
AY
AXY
A
StringBuilder sb = new StringBuilder("abc");
sb.reverse().append("x").reverse();
System.out.print(sb);
abcx
cbax
xabc
error
String s = "1a2b3c";
s = s.replaceAll("\\d", "");
System.out.print(s.length());
6
5
4
3
String s = "HELLO";
s.toLowerCase();
System.out.println(s);
HELLO
hello
hELLO
Hello
String s = "banana";
System.out.println(s.indexOf("na", 3));
2
3
4
-1
StringBuilder sb = new StringBuilder("abc");
String s = sb.toString();
sb.append("d");
System.out.println(s);
abc
abcd
error
d
static void fun(String s, int i) {
if(i == s.length()) return;
fun(s, i + 1);
System.out.print(s.charAt(i));
}
public static void main(String[] args) {
fun("abcd", 0);
}
0
abcd
dcba
a
static String solve(String s) {
if(s.length() <= 1) return s;
return solve(s.substring(1)) + s.charAt(0);
}
public static void main(String[] args) {
System.out.println(solve("java"));
}
avaj
java
j
a
