Answer to Question #255266 in Java | JSP | JSF for Dolly

Question #255266

Create a program that takes in a sentence from user input, the program then removes the last word and first word in the sentence. The remaining string is converted to upper case then printed out. [Hint: In case there is only two words, an empty line is printed]

 

Sample run 1:                    Sample run 2:

Enter a sentence: Hello There       Enter a sentence: Happy Thursday Everyone

Output:                          Output: THURSDAY

1
Expert's answer
2021-10-23T03:03:40-0400
import java.util.*;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    Scanner input=new Scanner(System.in);
	    String m=input.next();
	    String S=input.nextLine();
	    S=S.toUpperCase();
        int index= S.lastIndexOf(" ");
        System.out.println(S.substring(0, index));
	}
}

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