your logic is a confusing one. Here give you an example here to deal with this type of problem:public static void main(String[] args) throws Exception{ //temp = reader.readerLine(); String temp="a piggy loves\r\t\r\ran\tegg\r\n"; char ch; int cnt = 0; String word ="";
while ((ch=temp.charAt(cnt++)) != '\n'){ if((ch>='a'&& ch<='z')||(ch>='A'&&ch<='Z')) word = word + ch; else{ if(!word.equals("")) System.out.println(word); //push to the stack here word = ""; } } }
//temp = reader.readerLine();
String temp="a piggy loves\r\t\r\ran\tegg\r\n";
char ch;
int cnt = 0;
String word ="";
while ((ch=temp.charAt(cnt++)) != '\n'){
if((ch>='a'&& ch<='z')||(ch>='A'&&ch<='Z'))
word = word + ch;
else{
if(!word.equals(""))
System.out.println(word); //push to the stack here
word = "";
}
}
}