Answer to Question #58691 in Java | JSP | JSF for mike

Question #58691
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-03-25T10:23:04-0400
import java.util.Scanner;

public class Main
{
public static void main (String[] args)
{

Scanner sc = new Scanner(System.in);

System.out.println("Please enter a three word phrase as one string");
String str = sc.nextLine();

System.out.println("The number of characters (including spaces) in the phrase - "+str.length());

String[] arr=str.split(" ");
System.out.println("The number of characters in the middle word - "+arr[1].length());

System.out.println("The final word in all upper case - "+arr[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
APPROVED BY CLIENTS