0

What the error in this program to count number of words

public class Program { public static void main(String[] args) { String s; int count=0; s="java is the best"; for(int i=0;i<s.length()-1;i++) { if((s.charAt(i)) = " ") count =count+1; } System .out.println (count); } }

8th Jan 2022, 5:04 PM
Wen Will
Wen Will - avatar
2 Réponses
+ 2
Wen Will There should be double equal (==) for comparison. Single equal (=) is used to assign value. Also you are comparing character so there should be ' ' instead of " "
8th Jan 2022, 5:12 PM
A͢J
A͢J - avatar
+ 1
A͢J thank you
8th Jan 2022, 5:20 PM
Wen Will
Wen Will - avatar