153k views
1 vote
Suppose we have a String object called myString. Write a single line of Java code

that will output myString in such a way that all of its characters are uppercase.

1 Answer

6 votes

Answer:

myString=myString.toUpperCase();

Step-by-step explanation:

In java to change all characters of a string to upper case we use .toUpperCase() method.It will convert string to upper case.

Implementation in java.

import java.util.*;

class Solution

{

public static void main (String[] args) throws java.lang.Exception

{

try{

Scanner scr=new Scanner(System.in);

System.out.print("Enter a string:");

String myString=scr.nextLine();

myString=myString.toUpperCase();

System.out.println("string in upper case : "+myString);

}catch(Exception ex){

return;}

}

}

Output:

Enter a string:hello

string in upper case : HELLO

User Ncank
by
5.2k points