Trying to have an output repeat

  • Thread starter Thread starter magnifik
  • Start date Start date
  • Tags Tags
    Output
AI Thread Summary
To make a string repeat itself a specified number of times in programming, a function can be created that parses the input string to extract both the number and the character. For example, an input of "3y" would require the function to identify '3' as the repeat count and 'y' as the character to be repeated. It's important to establish clear specifications for the input format to avoid ambiguity, such as distinguishing between '33y' (33 times 'y') and '3y' (3 times 'y'). The function should handle different input scenarios to ensure accurate output. Properly defining the input and output requirements is crucial for effective string manipulation.
magnifik
Messages
350
Reaction score
0
How do you make a string repeat itself for a given number of times?
For example, if I wanted to make "3y" print out "yyy" on the screen (it prints "y" 3 times because the number in the input is 3).. how would i do this using functions?
 
Physics news on Phys.org
you could just parse the input string; but of course, you will need to include some specifications, or the input/output you want can be very vague ('33y') can be 33 times of y or 3 times of 3y.
 

Similar threads

Replies
4
Views
5K
Replies
2
Views
2K
Replies
6
Views
2K
Replies
1
Views
2K
Replies
10
Views
2K
Replies
31
Views
3K
Replies
2
Views
1K
Back
Top