+ 14
🏆🏆[Challenge] counting no. of spaces🏆🏆
Write a code to count the number of spaces in a word. code asks for user input. ex:- i love to learn coding in sololearn. no. of spaces:- 6 any language welcome
21 Antworten
+ 19
JavaScript:
alert(prompt("").split(" ").length - 1);
+ 10
python:
print(input().count(' '))
+ 8
in Java:
System.out.println(new Scanner(System.in).nextLine().split(" ").length-1);
+ 7
int a = 0;
char [] chars = Console.ReadLine().ToCharArray();
foreach(char c in chars)
if(c == ' ')
++a;
Console.Write(a);
+ 7
Ruby:
puts gets.count(" ")
# can it be more simple?
# written in my iPhone 8 (jk, irony intended)
+ 6
https://code.sololearn.com/cdtyC59c4mx4/?ref=app
+ 5
Using Ruby ..
https://code.sololearn.com/cPamMj8319ve/#rb
+ 5
My solution:
https://code.sololearn.com/WAj93C1bQfMk/?ref=app
+ 5
https://code.sololearn.com/cn2Yozicvy9W/?ref=app
+ 5
Python :
print(input().count(' '))
+ 4
+ 4
@Вукан .. Another version
string userInput = Console.ReadLine();
int i = userInput.Split(' ').Length - 1;
Console.Write(i);
+ 3
print(input().split().length()+1)
+ 1
Here's my very late attempt...
https://code.sololearn.com/cx53207B12v3/?ref=app
+ 1
@Yash Thatte
Every space in between words is counted as one, so if there are multiple(more than 1) spaces between words like this "I love programming" , the output would be more than 2(it would be 6 since I have given 3 spaces between each pair of words).