In: Computer Science
in java
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 display the word with a double quotation mark ( " ) at the start and end of the word,
● displays the word with all characters whose index is odd in lower case and for the rest of the characters displaying a * instead of the character,
● finally displays the original word as it was entered by the user.
Based on the previous specifications your program should behave and look exactly as shown in the cases below. Your program should work for any word entered by the user, not just the ones in the samples.
Below illustrates how your program should behave and appear.
Note that ◦ symbol indicates a space and ↵ is a new line character. All words except for user input (in blue) must be exactly as indicated in the sample. Any extra “spaces” and/or “new lines” will be graded a wrong answer.
Source Code:
import java.util.Scanner;
class ex
{
public static void main(String[] args) {
Scanner input=new
Scanner(System.in);
System.out.print("Enter a word:
");
String word=input.next();
String org=word;
word=word.toUpperCase();
System.out.println('"'+word+'"');
word=word.toLowerCase();
for(int
i=0;i<word.length();i++)
{
if(i%2==0)
System.out.print("*");
else
System.out.print(word.charAt(i));
}
System.out.println();
System.out.println(org);
}
}
Sample input and output: