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