fork download
  1. import java.util.Scanner;
  2.  
  3. class Main {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. StringBuilder text = new StringBuilder();
  7.  
  8. while (sc.hasNextLine()) {
  9. text.append(sc.nextLine()).append("\n");
  10. }
  11. sc.close();
  12.  
  13. String str = text.toString();
  14. String target = "hello world";
  15. int count = 0;
  16. int index = 0;
  17.  
  18. while ((index = str.indexOf(target, index)) != -1) {
  19. count++;
  20. index += target.length();
  21. }
  22.  
  23. System.out.println(count);
  24. }
  25. }
  26.  
Success #stdin #stdout 0.14s 54632KB
stdin
During my journey as a programmer, I started with the classic phrase HELLO WORLD.
Some people write it as Hello world, others as hello WORLD or even HeLLo WoRlD!
I once saw someone type hello  world with weird spacing or hello-world with a dash.
Another wrote: "hello, world" with a comma. My friend wrote it in a sentence like: When I wake up I say hello world before breakfast. But not everything is a greeting—sometimes it's in code: System.out.println("HELLO WORLD"); or commented like // hello world.
Even hidden inside text like aHELLO WORLDb or ending a paragraph with hello world...
stdout
3