Didart

Repeat String

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