Write a fragment of code that will read words from the keyboard until the word done is entered. For each word except done, report whether its first character is equal to its last character. For the required loop, use a
a. while statement
b. do-while statement
```
Scanner reader = new Scanner(System.in);
String word = "";
System.out.println("Please enter words ending with done.");
word = reader.next();
while(!word.equals("done")){
if(word.charAt(0) == word.charAt(word.length()-1)){
System.out.println("The word " + word
+ " has first and last characters that are the same.");
}
word = reader.next();
}
System.out.println("Please enter words ending with done.");
boolean finished = false;
do{
word = reader.next();
if(word.equals("done"))
finished = true;
else
if(word.charAt(0) == word.charAt(word.length()-1)){
System.out.println("The word " + word
+ " has first and last characters that are the same.");
}
} while (!finished);
```
This code is in Fragments.java.
You might also like to view...
When a parameter is passed call by value, what functions are guaran teed to be called?
a. zero-parameter constructor b. copy constructor c. destructor d. operator= e. two or more of the above
When you click through to the end of a presentation, ________ displays
A) a black slide B) a white screen C) an End message D) the Microsoft logo
The "W" in the standard 10GBaseSW stands for which type of signaling?
A. LAN B. wireless C. SONET/WAN D. radio
Describe asymmetric cryptography. Compare it to symmetric cryptography.
What will be an ideal response?