Answer to Question #57918 in Java | JSP | JSF for kenya

Question #57918
Prompt the user to enter a three word phrase as one string and then:

Display the number of characters (including spaces) in the phrase.
Display the number of characters in the middle word.
Display the final word in all upper case.
1
Expert's answer
2016-02-19T08:00:29-0500
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a three word phrase as one string:");
String string;
String[] test;
do {
string = sc.nextLine();
test = string.trim().split("\\s+");
if(test.length != 3){
System.out.println("You enter not three word phrase!");
}
}while(test.length != 3);
System.out.println("The number of characters (including spaces) in the phrase: " + string.length());
System.out.println("The number of characters in the middle word: " + test[1].length());
System.out.println("The final word in all upper case: " + test[2].toUpperCase());
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS