Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Java | Functions | Question 11

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Predict the output of the following program.




class Test
{
    public static void main(String[] args)
    {
        String str = "geeks";
        str.toUpperCase();
        str += "forgeeks";
        String string = str.substring(2,13);
        string = string + str.charAt(4);;
        System.out.println(string);
    }
}

(A) eksforgeekss
(B) eksforgeeks
(C) EKSforgeekss
(D) EKSforgeeks


Answer: (A)

Explanation: str.toUpperCase() returns ‘str’ in upper case. But,it does not change the original string ‘str’.
str.substring(x, y) returns a string from position ‘x'(inclusive) to position ‘y'(exclusive).
str.charAt(x) returns a character at position ‘x’ in the string ‘str’.

Quiz of this Question

My Personal Notes arrow_drop_up
Last Updated : 24 May, 2019
Like Article
Save Article
Similar Reads