Advertisement
veronikaaa86

07. Repeat String

Jun 8th, 2022
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. package methods;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P07RepeatString {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String textInput = scanner.nextLine();
  10. int n = Integer.parseInt(scanner.nextLine());
  11.  
  12. System.out.println(repeatString(textInput, n));
  13. }
  14.  
  15. public static String repeatString(String textToRepeat, int n) {
  16. String result = "";
  17. for (int i = 1; i <= n; i++) {
  18. result += textToRepeat;
  19. }
  20.  
  21. return result;
  22. }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement