Computer Science, asked by sanikadey1506, 7 months ago

Write a program to input a sentence and print the penultimate word of this sentence. Penultimate

word is the second last word of a sentence. (Assume that the Sentence is of 2 or more words)

E.g. Input : The quick brown fox jumps over a lazy dog. Output : lazy​

Answers

Answered by mdd19203
1

Explanation:

import java.util.*;

public class Exercise60 {

public static void main(String[] args){

Scanner in = new Scanner(System.in);

System.out.print("Input a Sentence: ");

String line = in.nextLine();

String[] words = line.split("[ ]+");

System.out.println("Penultimate word: "+words[words.length - 2]);

}

}

Answered by imtiyazallam
0

Answer:

words = (input("Enter a sentence: ")).split(" ")

print(word[-2])

Similar questions
Science, 3 months ago