Advertisement
veronikaaa86

07. Repeat String

May 31st, 2023
1,232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 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.         String resultText = repeatString(n, textInput);
  13.  
  14.         System.out.println(resultText);
  15.     }
  16.  
  17.     public static String repeatString(int n, String textToRepeat) {
  18.         String resultText = "";
  19.         for (int i = 0; i < n; i++) {
  20.             resultText += textToRepeat;
  21.         }
  22.  
  23.         return resultText;
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement