Write a Java program to find the penultimate (next to last) word of a sentence
- برمجة جافا
- برمجة
- 2021-05-01
- razanmazen8711884270
الأجوبة
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]);
}
}
Sample Output:
Input a Sentence: The quick brown fox jumps over the lazy dog. Penultimate word: lazy
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال