Skip to content

Commit 5f7364b

Browse files
committed
Count number of words in a string
1 parent 225608a commit 5f7364b

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

Count_Word.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
/* Count number of word in a string
2+
*Note : Always ignore the spaces if more than 1 space given between two word
3+
4+
Sample Input : 1
5+
------------------------
6+
Kalyani Goverment Engineering College
7+
8+
Process
9+
---------------------------
10+
[Kalyani, Goverment, Engineering, College]
11+
12+
Output
13+
---------------------------
14+
Number of word : 4
15+
*************************************
16+
Sample Input : 2
17+
------------------------
18+
Kalyani Goverment Engineering College
19+
20+
Process
21+
---------------------------
22+
[Kalyani, Goverment, , Engineering, College]
23+
24+
Output
25+
---------------------------
26+
Number of word : 4
27+
*/
28+
129
import java.util.*;;
230
public class Count_Word
331
{
@@ -7,7 +35,7 @@ public static void main(String[] args)
735
String s = sc.nextLine();
836
String[] arr = s.split(" ");
937
int count=0;
10-
System.out.println(Arrays.toString(arr));
38+
//System.out.println(Arrays.toString(arr));
1139
for (int i = 0; i < arr.length; i++) {
1240
if(arr[i]!="")
1341
{

0 commit comments

Comments
 (0)