write a program to enter a string like"sunil is a good boy
and seeking for a job" not more than 10 characters including
space in one line,rest characters should b in other line.if
the next line starts from in between the previous word,then
print whole word to next line.



write a program to enter a string like"sunil is a good boy and seeking for a job" not mor..

Answer / Rahul Chaudhary

Here's an example in Python that illustrates the desired functionality:

input_string = "sunil is a good boy and seeking for a job"
words = input_string.split() # Split the string by whitespace
output_string = ""
for word in words:
if len(output_string) == 0 or (len(output_string.split("n")[-1]) + len(word) + 1 > 10): # Check if current line is full or there's space to add the word
output_string += f"{word}n" # If there's space, add the word with a newline
else: # If the current line is full, print the whole line and start a new one
output_string += f"{output_string.split('n')[-1]} " # Print the last word of the previous line without the newline character
output_string += f"n{word}" # Add the next word with a newline

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More OOPS Interview Questions

Write a program in c++ to read two floating point numbers and find their sum and average.

2 Answers  


What are the three parts of a simple empty class?

1 Answers  


1. Define a class.

6 Answers  


why we are declare the function in the abstract class even though we are declaring it in Derived class?

1 Answers   TCS,


What is the difference between pass by reference and pass by value?

12 Answers   Pfizer, TCS,


what is the size of an empty class

12 Answers   Wipro,


What is property in oops?

1 Answers  


string is a class or data type in java?

3 Answers  


can inline function declare in private part of class?

2 Answers  


What is multilevel inheritance?

1 Answers  


What is multilevel inheritance in oop?

1 Answers  


What are the features of oop?

1 Answers  


Categories