Computer Science, asked by Subhadeepzehen, 1 year ago

write a program to count number of spaces present in a string​

Answers

Answered by mersalkeerthi46
1

int count=0;

   String arr[]=s.split("\t");

   OOPHelper.println("Number of spaces are: "+arr.length);

   count++;

Answered by Equestriadash
6

string = input("Enter a string: ")

cspace = 0

for i in string:

 if i == " ":

   cspace = cspace + 1

print("There are ", cspace, "spaces in the string.")

Once the string is entered by a user, the loop starts. The variable 'i' traverses through each character in the range value, and if it satisfies the succeeding condition, the count variable increments by 1.

Attachments:
Similar questions