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.
2 parents bba6735 + df20459 commit 7b2224aCopy full SHA for 7b2224a
.DS_Store
2 KB
countwords.java
@@ -0,0 +1,19 @@
1
+import java.util.Scanner;
2
+class CountTheWords
3
+{
4
+ public static void main(String args[])
5
+ {
6
+ System.out.println("Enter the string");
7
+ Scanner sc = new Scanner(System.in);
8
+ String s=sc.nextLine();
9
+ int count = 1;
10
+ for (int i = 0; i < s.length()-1; i++)
11
12
+ if((s.charAt(i) == ' ') && (s.charAt(i+1) != ' '))
13
14
+ count++;
15
+ }
16
17
+ System.out.println("Number of words in the string = "+count);
18
19
+}
0 commit comments