java - BufferedReader not taking input even after pressing enter -


public static void main (string args[]) throws ioexception{      bufferedreader br = new bufferedreader(new inputstreamreader(system.in));     system.out.println("enter string");     string s = br.readline();     s=s+" ";     s.tolowercase();     string word="";     string max="";     int count=0;      for(int i=0; i<s.length();i++){         char ch = s.charat(i);         while(ch!=' ')             word+=ch;          if(word.length()>max.length()){             max=word; count++;         }         else count++;     }system.out.println(max+" , "+count); } } 

i want find biggest word in string without using split or , count how many words present in sentence. when input , press enter nothing happens. problem?

there no problem reading input console.

while(ch!=' ')     word+=ch; 

it makes infinite loop. should update while-loop -

while(ch!=' '){    word+=ch;    ch = s.charat(++i); } 

Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -