Advertisement
CoineTre

JF-LabMethods07.Repeat String

Feb 5th, 2021
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Lab7RepeatString {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String text = scanner.nextLine();
  7.         int counter = Integer.parseInt(scanner.nextLine());
  8.         String newString = getRepeatString(text,counter);
  9.     }
  10.  
  11.     private static String getRepeatString(String text, int counter) {
  12.         for (int i = 0; i < counter ; i++) {
  13.             System.out.print(text);
  14.         }
  15.         return text;
  16.     }
  17. }
  18. /*Write a method that receives a string and a repeat count n (integer).
  19.  The method should return a new string (the old one repeated n times).*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement