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 b0027cd commit df20459Copy full SHA for df20459
countwords.java
@@ -1,23 +1,19 @@
1
+import java.util.Scanner;
2
class CountTheWords
3
{
- public static void main(String[] args)
4
+ public static void main(String args[])
5
6
System.out.println("Enter the string");
-
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++)
+ int count = 1;
+ for (int i = 0; i < s.length()-1; i++)
14
15
if((s.charAt(i) == ' ') && (s.charAt(i+1) != ' '))
16
17
- count++;
+ count++;
18
}
19
20
21
- System.out.println("Number of words in a string = "+count);
+ System.out.println("Number of words in the string = "+count);
22
23
0 commit comments