In: Computer Science
Problem: Read in a word and display the requested characters from that word in the requested format. Write a Java program that
● prompts the user for a word and reads it,
● converts all characters of the input word to uppercase and displays every other character starting from the 1st one,
● converts all characters of the input word to lowercase and displays every other character in reverse order starting from the last character,
● finally displays the original word as it was entered by the user.
ANSWER:--
GIVEN THAT:--
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner myObj = new
Scanner(System.in); // Create a Scanner object
System.out.print("Input The Word : ");
String word =
myObj.nextLine(); // original word
String tempword = new String(word); // temporary storage
tempword = tempword.toUpperCase();
System.out.print("\nThe word in CAPS : ");
for (int i = 0; i <
tempword.length(); i += 3)
System.out.print(tempword.charAt(i));
tempword = tempword.toLowerCase();
String rev = "";
for (int i =
tempword.length() - 1; i >= 0; --i)
rev += tempword.charAt(i);
System.out.print("\nThe word in reverse : ");
System.out.print(rev);
System.out.print("\nThe original word : ");
System.out.print(word);
myObj.close();
}
}