Advertisement
Guest User

Untitled

a guest
Sep 15th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class CS123Ass3ID4309
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner keyboard = new Scanner(System.in);
  8. System.out.println("Please enter a sentence without punctuation");
  9. //Keyboard input
  10. String test = keyboard.nextLine();
  11. //detects the first word in the string
  12. String firstWord = test.substring(test.indexOf(" ")-1);
  13. //detects the last word in the string
  14. String lastWord = test.substring(test.lastIndexOf(" ")+1);
  15.  
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement