Advertisement
veronikaaa86

07. Repeat String

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