nd it seems u may be mistaken.. i just ran ur program and everything seems 2 work fine.
Entered
Professor albus
MR weasly
Ms Granger
Harry Potter
Professor Albus Percival Wulfric Brian Dumbledore
pRoFeSsOr Minerva McGonagall
ProfessorSnape
Professo
Welcome professor
Welcome visitor
Welcome visitor
Welcome student
Welcome professor
Welcome professor
Welcome professor
Welcome student
it all seems to run fine... however one thing i noticed.. if u hit enter a blank line.. then the program return student.. maybe thats the problem u where having? it looks like u hit enter twice after every entry
------------
Professor albus
MR weasly
Ms Granger
Harry Potter
Welcome professor
Welcome student ---
Welcome visitor
Welcome student ---
Welcome visitor
Welcome student ---
Welcome student
Welcome student ----
sooo if we want to fix the program a simple edit 2 the for loop is needed (i think this should work ---->
CODE
for(int i=0;i<20;i++)
{
String s = buf.readLine();
if(s.equals(" ")){
break;
}
else if(s.equals("")){ //a simple check..
i--;
}
else{
s1[i]=s.toLowerCase();
count++;
}
}
now another little thing that could be improved in ur program:
the if statments that decide what welcome message 2 print could be a shortened a little..
CODE
for(int i=0;i<count;i++){
if(s1[i].startsWith(s3)){
System.out.println("Welcome professor");
}
else if((s1[i].startsWith(s4))||(s1[i].startsWith(s5))){
System.out.println("Welcome visitor");
}
else {
System.out.println("Welcome student");
}
}
This post has been edited by gl3thr0: 1 Jul, 2008 - 11:40 AM