java - Code won't display "The" just keeps printing out everything -


so, doing project class. can't code print out want. keeps printing out whole entire "poem".

nerddata.txt :

     every man tries hard can.      best way way.      schedule good.      cosmo kramer doofus.          best movie cancelled. 

what got far:

import java.util.*; import java.io.*; public class filenerd { public static void main(string args[]) throws ioexception {     scanner sf = new scanner(new file("c:\\temp_timmy\\nerddata.txt"));      int maxindx = -1;     string text[] = new string[1000];     while(sf.hasnext( ))     {         maxindx++;         text[maxindx] = sf.nextline( ) ;     }     sf.close( );     for(int j = 0; j <= maxindx; j++)     {         string q = text[j];         system.out.println(q);          if( q.substring(3).equals("the")) {             system.out.println(q);         }     }    } } 

code compiles fine doesn't print out lines begin word "the" prints out whole entire poem.

the output want:

the best way way. schedule good. best movie cancelled. 

here printing every line

 string q = text[j];  system.out.println(q);   // try remove 

also consider using string.startswith substring wrong*

if (q.startswith("the")) {     system.out.println(q); } 
  • as per javadcos "harbison".substring(3) returns "bison"