Computer Science, asked by akashanandnair7777, 3 months ago

pls help me with the answer​

Attachments:

Answers

Answered by anindyaadhikari13
1

Required Answer:-

Question:

  • Write a program to input a string and display all the words whose length is 5.

Solution:

Here comes the solution.

1. In Java.

import java.util.*;

public class StringOp {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

System.out.print("Enter a String: ");

String s[]=sc.nextLine().split(" ");

for(String x:s) {

if(x.length()==5)

System.out.println(x);

}

sc.close();

}

}

2. In Python.

s=input("Enter a string: ").split(" ")

for word in s:

if len(word)==5:

print(word)

Algorithm:

  1. START
  2. Accept the sentence.
  3. Split the sentence into words.
  4. Count the length of each word and if the length is 5, display it.
  5. STOP

Refer to the attachment for output ☑.

Attachments:
Similar questions