pls help me with the answer
Attachments:
Answers
Answered by
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:
- START
- Accept the sentence.
- Split the sentence into words.
- Count the length of each word and if the length is 5, display it.
- STOP
Refer to the attachment for output ☑.
Attachments:
Similar questions