We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8c38c60 commit b0027cdCopy full SHA for b0027cd
.DS_Store
2 KB
countwords.java
@@ -0,0 +1,23 @@
1
+class CountTheWords
2
+{
3
+ public static void main(String[] args)
4
+ {
5
+ System.out.println("Enter the string");
6
+
7
+ Scanner sc = new Scanner(System.in);
8
9
+ String s=sc.nextLine();
10
11
+ int count = 1;
12
13
+ for (int i = 0; i < s.length()-1; i++)
14
15
+ if((s.charAt(i) == ' ') && (s.charAt(i+1) != ' '))
16
17
+ count++;
18
+ }
19
20
21
+ System.out.println("Number of words in a string = "+count);
22
23
+}
0 commit comments