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.
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!
Learn more about our help with Assignments:
JavaJSPJSF