223k views
4 votes
Write a program that prompts the user to input a string and outputs the string in uppercase letters. (Use a character array to store the string.)

User Farahmand
by
6.3k points

1 Answer

3 votes

Answer:

Step-by-step explanation:

The following code is written in Java. It asks the user for a string/sentence and then grabs every character in the string, capitalizes it, and saves it in a char ArrayList. Then it concatenates the char array into a String variable called output and prints the capitalized String.

public static void capitalizeMe() {

Scanner in = new Scanner(System.in);

System.out.println("Enter a String:");

String inputSentence = in.nextLine();

ArrayList<Character> capitalString = new ArrayList<Character>();

for (int x = 0; x < inputSentence.length(); x++) {

capitalString.add(Character.toUpperCase(inputSentence.charAt(x)));

}

String output = "";

for (char x: capitalString) {

output += x;

}

System.out.println(output);

}

User Tobinharris
by
6.4k points