+ 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

8th Oct 2017, 2:28 AM
Abhishek Pun
Abhishek Pun - avatar
21 Antworten
+ 19
JavaScript: alert(prompt("").split(" ").length - 1);
8th Oct 2017, 2:59 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 10
python: print(input().count(' '))
8th Oct 2017, 6:02 AM
Aravind Shetty
Aravind Shetty - avatar
+ 8
in Java: System.out.println(new Scanner(System.in).nextLine().split(" ").length-1);
10th Oct 2017, 6:21 AM
LukArToDo
LukArToDo - avatar
+ 7
int a = 0; char [] chars = Console.ReadLine().ToCharArray(); foreach(char c in chars) if(c == ' ') ++a; Console.Write(a);
8th Oct 2017, 8:57 AM
Vukan
Vukan - avatar
+ 7
Ruby: puts gets.count(" ") # can it be more simple? # written in my iPhone 8 (jk, irony intended)
11th Oct 2017, 9:58 AM
noobcøder
noobcøder - avatar
+ 6
https://code.sololearn.com/cdtyC59c4mx4/?ref=app
11th Oct 2017, 4:14 AM
qwerty
qwerty - avatar
8th Oct 2017, 6:48 AM
A Z I Z
A Z I Z - avatar
10th Oct 2017, 12:23 PM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 5
https://code.sololearn.com/cn2Yozicvy9W/?ref=app
10th Oct 2017, 3:31 PM
Emma
+ 5
Python : print(input().count(' '))
11th Oct 2017, 10:19 AM
Chinmoy
Chinmoy - avatar
8th Oct 2017, 2:58 AM
LunarCoffee
LunarCoffee - avatar
+ 4
@Вукан .. Another version string userInput = Console.ReadLine(); int i = userInput.Split(' ').Length - 1; Console.Write(i);
8th Oct 2017, 9:24 AM
A Z I Z
A Z I Z - avatar
11th Oct 2017, 11:46 AM
ⵢⴷⵢⴷ
ⵢⴷⵢⴷ - avatar
+ 3
print(input().split().length()+1)
11th Oct 2017, 10:30 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
13th Oct 2017, 11:18 AM
Amandeep Singh
Amandeep Singh - avatar
+ 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).
13th Oct 2017, 11:31 AM
Amandeep Singh
Amandeep Singh - avatar