Penultimate word in a sentence

Penultimate word in a sentence

Write a program which finds the next-to-last word in a string.

Example 1:


input data:
this is a sample sentence
output:
sample

Example 2:


input data:
Both adventure and adventist are pretty long words
output:
long
View Code Template
View Java Solution

Seda
Seda Kunda is a web designer and developer with a degree in Computer Science and a great passion for code. Besides code, she enjoys pepperoni pizza, watching the bachelor and sleeping in on Saturdays.
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn