veronikaaa86

07. Repeat String

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