Java String Kuizi 2-ci hissə

Bu kuiz Java stringlər haqqında biliklərinizi yoxlamaq və möhkəmləndirmək üçün faydalı olacaqdır. Uğurlar!

24 Sentyabr 2024 - 16:07
 0  114

1. Aşağıdakı kodun nəticəsi nə olacaq?

public class Test {
    public static void main(String[] args) {
        String str = "Hello";
        str += " World";
        str.trim();
        System.out.println(str.length());
    }
}

5
10
11
6

2. Aşağıdakı kodun nəticəsi nə olacaq?

public class Test {
    public static void main(String[] args) {
        String str1 = "abc";
        String str2 = "ABC".toLowerCase();
        System.out.println(str1 == str2);
        System.out.println(str1.equals(str2));
    }
}

true true
true false
false true
false false

3. Aşağıdakı kodun nəticəsi nə olacaq?

public class Test {
    public static void main(String[] args) {
        String str = "ABCD";
        str = str.concat(str);
        str = str.substring(1, 5);
        System.out.println(str);
    }
}

ABCD
BCDA
BCDB
BCAB

4. Aşağıdakı kodun nəticəsi nə olacaq?

public class Test {
    public static void main(String[] args) {
        String str = null;
        String result = str + "test";
        System.out.println(result);
    }
}

NullPointerException
null
test
nulltest

5. Aşağıdakı kodun nəticəsi nə olacaq?

public class Test {
    public static void main(String[] args) {
        String str1 = "abc";
        String str2 = "abc";
        String str3 = "ab" + "c";
        System.out.println(str1 == str2);
        System.out.println(str1 == str3);
    }
}

true true
true false
false true
false false

6. Aşağıdakı kodun nəticəsi nə olacaq?

public class Test {
    public static void main(String[] args) {
        String s1 = "test";
        String s2 = s1.toUpperCase();
        String s3 = s2.toLowerCase();
        System.out.println(s1 == s3);
    }
}

true
false
Compile time xətası
Runtime xətası

7. Aşağıdakı kodun nəticəsi nə olacaq?

public class Test {
    public static void main(String[] args) {
        String str = "Java";
        str = str.replace('a', 'o');
        System.out.println(str);
    }
}

Jova
Jv
Java
Jovo

8. Aşağıdakı kodun nəticəsi nə olacaq?

public class Test {
    public static void main(String[] args) {
        String s1 = "abc";
        String s2 = new String("abc");
        s2 = s2.intern();
        System.out.println(s1 == s2);
    }
}

true
false
Compile time xətası
Runtime xətası

9. Aşağıdakı kodun nəticəsi nə olacaq?

public class Test {
    public static void main(String[] args) {
        String str1 = "abc";
        String str2 = "abc";
        String str3 = new String("abc");
        System.out.println(str1.hashCode() == str3.hashCode());
        System.out.println(str1 == str2);
        System.out.println(str1 == str3);
    }
}

true true true
true true false
true false false
false true false

10. Aşağıdakı kodun nəticəsi nə olacaq?

public class Test {
    public static void main(String[] args) {
        String str = "Hello";
        String reversed = new StringBuilder(str).reverse().toString();
        System.out.println(reversed);
    }
}

Hello
olleH
Compile time xətası
ClassCastException xətası