+ 8

🏆🏆challenge [Word Count]🏆🏆 Write a program to count Words in a string. Using Only Loops..

example1: Hello I'm good developer. Answer : 4 example2: Hello sir how are you. Answer : 5 //Without Function

5th Nov 2017, 12:59 PM
P∆WAN M∆URY∆
P∆WAN M∆URY∆ - avatar
17 ответов
+ 14
Here is my answer using java. First I consider a random sequence of characters (with some blank spaces) as the input and count the number of words in this sentence. Then I consider a fixed paragraph of correct English words and again count the number of words. https://code.sololearn.com/cDj2uAxH8BEq
6th Nov 2017, 1:24 PM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
+ 9
https://code.sololearn.com/c6IVWIm3Oy4T/?ref=app
5th Nov 2017, 2:07 PM
Podretyz
Podretyz - avatar
5th Nov 2017, 4:54 PM
David Akhihiero
David Akhihiero - avatar
+ 9
Here's my try : edit: without trim() function https://code.sololearn.com/c1xLfCwSqjfD/?ref=app
6th Nov 2017, 12:35 PM
LukArToDo
LukArToDo - avatar
+ 7
# Python: str = "Hello, there!" c, s = 0, 0 for i in str: if i == ' ' or i == '\n' or i == '\t': s = 0 elif s == 0: s = 1 c+=1 print(c) # Output: 2
5th Nov 2017, 4:41 PM
Kartikey Sahu
Kartikey Sahu - avatar
+ 7
Here is my code.....some days before I posted the same challenge....and i made this code at that time.... https://code.sololearn.com/cm2B62Jf6HyS/?ref=app
5th Nov 2017, 5:10 PM
Sanjeev Kumar
Sanjeev Kumar - avatar
5th Nov 2017, 1:07 PM
Αητοιπe
Αητοιπe - avatar
5th Nov 2017, 2:34 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
6th Nov 2017, 9:21 PM
Ferhat Sevim
Ferhat Sevim - avatar
+ 3
This is the easiest way I found of doing it, and I used a For loop. Check it out: https://code.sololearn.com/cY6WzBAxt0oT/?ref=app
6th Nov 2017, 10:59 PM
Jonathan Álex
Jonathan Álex - avatar
+ 3
import java.util.Scanner; public class WordCount { public static void main(String[] args) { int countword = 0; Scanner inpt = new Scanner(System.in); while (inpt.hasNext()) { String w = new String(inpt.next()); countword++;} System.out.println(countword + " - words"); } }
24th Dec 2017, 4:47 AM
Dick Tracy
Dick Tracy - avatar
+ 3
my word counter in js. without using function. https://code.sololearn.com/WE8QDKg00KuA/?ref=app
2nd Mar 2018, 7:36 PM
UnknownYmous
+ 2
@Antoine Begerault input this string and Check😬your Result. i am java Programmer .
5th Nov 2017, 1:11 PM
P∆WAN M∆URY∆
P∆WAN M∆URY∆ - avatar
7th Nov 2017, 6:48 PM
Giorgos Athanasias
Giorgos Athanasias - avatar
0
count=0 str=input ("enter a string") n=len (str) for i in n: if (i=' 'ori='\t'ori='\n'): count=count+1 print (count)
8th Nov 2017, 3:55 AM
Divya sree Chowdary
Divya sree Chowdary - avatar
0
x = "this is an awesome text" def prog3(string): l = list() for texto in string.split(): l.append(len(texto)) if len(texto) == max(l):win=texto print(win) prog3(x)
22nd Jan 2021, 8:20 PM
Javier Salcedo
Javier Salcedo - avatar