HarrJ

Day 09 string A

Feb 9th, 2024
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. public class Day09A {
  2. public static void main(String[] args) {
  3. String txtSource = "The quick brown fox jumps the lazy dog.";
  4. int currentIndex = 0;
  5.  
  6. System.out.println("current source: " + txtSource);
  7. currentIndex = txtSource.toLowerCase().indexOf("the");
  8. System.out.println("find index of \"the\": " + currentIndex);
  9. // txtSource = txtSource.toLowerCase();
  10. currentIndex = txtSource.toLowerCase().indexOf("the",currentIndex+1);
  11. System.out.println("find index of \"the\": " + currentIndex);
  12.  
  13. txtSource = "She sells sea shells by the sea shore. The shells she sells are surely sea shells. So if she sells shells on the sea shore, I'm sure she sells seashore shells.";
  14.  
  15. System.out.println("current source: " + txtSource);
  16. int sourceLen = txtSource.length();
  17. currentIndex = 0;
  18. int count = 0;
  19.  
  20. while (count < sourceLen) {
  21. System.out.print("the word sea is on index ");
  22. currentIndex = txtSource.toLowerCase().indexOf("sea", count);
  23. System.out.println(currentIndex);
  24. count++;
  25. }
  26.  
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment