Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class CS123Ass3ID4309
- {
- public static void main(String[] args)
- {
- Scanner keyboard = new Scanner(System.in);
- System.out.println("Please enter a sentence without punctuation");
- //Keyboard input
- String test = keyboard.nextLine();
- //detects the first word in the string
- String firstWord = test.substring(test.indexOf(" ")-1);
- //detects the last word in the string
- String lastWord = test.substring(test.lastIndexOf(" ")+1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement