Write a java program to find Repeating set of characters in a string.

Get a string and a positive integer n as input. The last n characters should repeat the number of times given as second input.Write code to repeat the set of character from the given string.

The return type of the output is a string with repeated n characters.

Input and Output Format:

Input consists a string and a positive integer n.

Output is a string with repeated characters.

Refer sample output for formatting specifications.


Sample Input 1:



Sample Output 1:


Sample Input 2:



Sample Output 2:


Find the repeating set of characters in a string in Java.

import java.util.*;
public class Main {
                public static String lengthiestString(String s1,int n){
                                StringBuffer sb=new StringBuffer();
                                for(int i=0;i<n;i++)
        return sb.toString();
                public static void main(String[] args) {
                                Scanner s=new Scanner(System.in);
                                System.out.println("enter the String:");
                                String s1=s.nextLine();
                                int n=s.nextInt();
                                System.out.println("the lengthiest string is:"+lengthiestString(s1,n));

You May Also Like These Posts:

Leave a Reply

Your email address will not be published.

two × 5 =