What will be printed when the following code is executed? String firstname = "John"; String surname = "Smith"; surname.toUpperCase(); System.out.print(fir
Question
What will be printed when the following code is executed? String firstname = "John"; String surname = "Smith"; surname.toUpperCase(); System.out.print(fir
Solution
The code you provided is incomplete. It seems like you want to print the variable "firstname" but it got cut off. If you intended to print "firstname" after converting "surname" to upper case, it would still print "John" because the toUpperCase() method does not change the original string, it returns a new string. Also, you didn't assign the result of surname.toUpperCase() to any variable. Here is the corrected version of your code:
String firstname = "John";
String surname = "Smith";
surname = surname.toUpperCase();
System.out.print(firstname);
This will print "John". If you want to print the surname in uppercase, you should print the "surname" variable:
String firstname = "John";
String surname = "Smith";
surname = surname.toUpperCase();
System.out.print(surname);
This will print "SMITH".
Similar Questions
What will the following code print out when it is run?Scanner scnr = new Scanner("Hello \n\n World!");String c = scnr.next();String b = scnr.nextLine();String a = scnr.next();System.out.println(":" + a + ":" + b + ":");Group of answer choices:Hello:World!::World!: ::Hello: :: : World!:
What will be the output of the program?String s = "ABC"; s.toLowerCase(); s += "def"; System.out.println(s);ABCabcABCdefCompile Error
Consider the following code:public void displayNames(){ int i = 5; String[] names = new String[10]; System.out.println(names[i]);}What will be the output when displayNames executes?
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
Given the following method: static String saySomething(String name) { String output = ""; if (name.length() < 5) { output = name + ", your name is short."; } else { output = name + ", your name is long."; } return output; } What would the output be to the screen after following statement? System.out.println(saySomething("Randy"));Randy, your name is long.Randy, your name is short.RandysaySomething("Randy")
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.