Java Sorular 1
Java Sorular 1
Java Sorular 1
Java Questions
Starlang
11. What is the output of the following code? a) {10, 20, 30, 40}
int sum = 0;
b) {40, 10, 10, 10}
int i = 0; c) {40, 40, 40, 10}
while ( i < 5) { d) {10, 40, 40, 40}
sum = sum + i; e) {10, 10, 10, 10}
i ++;
} 15. What will be the output of the following pro-
System.out.println( i + ” ” + sum); gram?
a) 5 10 int sum = 0;
for ( int i = 1; i <= 10; i++){
b) 6 10 for ( int j = i ; j <= 10 − i; j ++){
c) 4 10 sum++;
d) 5 11 }
e) 6 11 }
System.out.println(sum);
12. Which of the following is the correct definiton
of a method? a) 55
1) public static void method() {} b) 110
2) public static void method(void) {} c) 15
3) public static method() {} d) 25
4) public static method(void) {} e) 10
a) 1, 2
16. Consider the following for loop
b) 1
c) 1, 2, 3 for (A; B; C){
d) 2, 4 }
e) 1, 2, 3, 4
How do you convert this for loop into a while loop?
a)
13. What will be the output of the following pro-
gram? A;
while (B){
int sum = 0; }
for ( int i = 1; i <= 5; i ++){ C;
for ( int j = 1; j <= 5; j++){ b)
for ( int k = 1; k <= 5; k++){
sum++; B;
} while (A){
} C;
} }
System.out.println(sum); c)
A;
a) 55 while (C){
b) 35 B;
c) 210 }
d) 50 d)
e) 125 A;
B;
14. What is the content of the array list after while (C){
executing the following code? }
int [] list = {10, 20, 30, 40}; e)
int tmp = list [ list .length − 1]; A;
for ( int i = 1; i < list .length; i ++) { while (B){
list [ i ] = list [ i − 1]; C;
} }
list [0] = tmp;
4