I am trying to make a program on word count which I have partially made and it is giving the correct result but the moment I enter space or more than one space in the string
This could be as simple as using split and count variable.
public class SplitString {
public static void main(String[] args) {
int count=0;
String s1="Hi i love to code";
for(String s:s1.split(" "))
{
count++;
}
System.out.println(count);
}
}