Advertisement
veronikaaa86

07. Repeat String

Oct 6th, 2021
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 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 input = scanner.nextLine();
  10. int n = Integer.parseInt(scanner.nextLine());
  11.  
  12. String result = repeatString(input, n);
  13.  
  14. System.out.println(result);
  15. }
  16.  
  17. public static String repeatString(String textToRepeat, int n) {
  18. String output = "";
  19. for (int i = 0; i < n; i++) {
  20. output += textToRepeat; //abcabcabc
  21. }
  22.  
  23. return output;
  24. }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement