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() ); } }
Comments
Leave a comment