116k views
1 vote
public class ChangeCase {public static void main(String args[]) {Scanner s = new Scanner(System.in); String sample; String result; System.out.println("Enter a string or done when you want to quit."); sample = s.nextLine(); while(sample.compareTo("done") != 0) { // Call () method here and print the result. System.out.println("Lowercase: " + result); // Call () method here and print the result. System.out.println("Uppercase: " + result); System.out.println("Enter a string or done when you want to quit."); sample = s.nextLine(); } System.exit(0); } // End of main() method. } // End of ChangeCase class.

1 Answer

2 votes

Answer:

The code you provided is the beginning of a Java program that prompts the user to enter a string and then converts that string to both lowercase and uppercase using methods that are not yet defined. Here is the modified code with the missing methods implemented:

Step-by-step explanation:

import java.util.Scanner;

public class ChangeCase {

public static void main(String args[]) {

Scanner s = new Scanner(System.in);

String sample;

String result;

System.out.println("Enter a string or 'done' when you want to quit.");

sample = s.nextLine();

while(sample.compareTo("done") != 0) {

// Call toLowerCase() method here and print the result.

result = sample.toLowerCase();

System.out.println("Lowercase: " + result);

// Call toUpperCase() method here and print the result.

result = sample.toUpperCase();

System.out.println("Uppercase: " + result);

System.out.println("Enter a string or 'done' when you want to quit.");

sample = s.nextLine();

}

System.exit(0);

}

}

User Trunst
by
8.6k points