can you help me why I got proper output though i have provided many spaces, this program is just counting the one space in if/ else condition
public class CountingtheCharactersinString
{
public static void main(String[] args)
{
String name = "This is my first demo";
int count = 0;
boolean b = true;
for(int i =0; i<name.length(); i++)
{
if(name.charAt(i)==' ') b = true;
else if(b==true)
{
b= false;
count = count+1;
}
}
System.out.println(count);
}
}