+ 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
17 Réponses
+ 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
+ 9
https://code.sololearn.com/c6IVWIm3Oy4T/?ref=app
+ 9
Here's my try :
edit: without trim() function
https://code.sololearn.com/c1xLfCwSqjfD/?ref=app
+ 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
+ 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
+ 5
Does this works ?
https://code.sololearn.com/WzYgr3edQN8e/?ref=app
+ 5
Nan...Nan da?!
https://code.sololearn.com/W6SIecbF7ZF9/?ref=app
+ 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
+ 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");
}
}
+ 3
my word counter in js.
without using function.
https://code.sololearn.com/WE8QDKg00KuA/?ref=app
+ 2
@Antoine Begerault
input this string and Check😬your Result.
i am java Programmer .
+ 2
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)
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)