What will be the output of the program?String s = "ABC"; s.toLowerCase(); s += "def"; System.out.println(s);ABCabcABCdefCompile Error
Question
What will be the output of the program?String s = "ABC"; s.toLowerCase(); s += "def"; System.out.println(s);ABCabcABCdefCompile Error
Solution
The output of the program will be "ABCdef".
Here's the step by step explanation:
-
The program starts by creating a String variable
sand assigning it the value "ABC". -
The
toLowerCase()method is called ons, which converts all the letters in the string to lower case. However, the result of this operation is not assigned to any variable, so it does not affect the original strings. -
The
+=operator is used to append "def" to the end ofs. Nowsis "ABCdef". -
Finally,
sis printed to the console. So, the output of the program is "ABCdef".
Similar Questions
What will be the output of the program?String x = "xyz";x.toUpperCase(); /* Line 2 */String y = x.replace('Y', 'y');y = y + "abc";System.out.println(y);abcXyZabcxyzxyzabcXyZabc
Select the correct answerWhat will be the output of the following Java program?class String_demo { public static void main(String args[]) { char chars[] = {'f', 'o', 'r'}; String s = new String(chars); System.out.println(s); }}Optionsfrforo
What will be the output of the below program?public class Test { public static void main(String[] args) { char c = 65; System.out.println("c = " + c); }} Note : explain clearly in the answer
Given the following lines of code, which of the following is the result of a user entering ABCDEFG when prompted?String stringValue = input.nextLine();char singleChar = stringValue.charAt(0);System.out.println(singleChar);a.)Bb.)Errorc.)Ad.)0
What will be the output of the following Java program? import java.io.*; class Chararrayinput { public static void main(String[] args) { String obj = "abcdefgh"; int length = obj.length(); char c[] = new char[length]; obj.getChars(0, length, c, 0); CharArrayReader input1 = new CharArrayReader(c); CharArrayReader input2 = new CharArrayReader(c, 1, 4); int i; int j; try { while((i = input1.read()) == (j = input2.read())) { System.out.print((char)i); } } catch (IOException e) { e.printStackTrace(); } } }A) abcB) abcdC) abcdeD) none of the mentioned
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.