You are viewing a single comment's thread. Return to all comments →
This is my solution
package hackerrankcode;
import java.io.; import java.math.BigInteger; import java.util.;
public class Repeated_String {
public static BigInteger repeat(String s,long n){ BigInteger min = new BigInteger("9223372036854775808"); BigInteger increment = new BigInteger("1"); List<Character> list=new ArrayList<>(); for(long i=0;i<s.length();i++){ list.add(s.charAt((int)i)); } //System.out.println("The list is: "+list); if(list.contains("a")){ // System.out.println("output from here"); BigInteger bigInteger=new BigInteger("0"); return bigInteger; }else if(n>=list.size() && n<=Math.pow(10, 6)){ int y=0; while(list.size()!=n){ list.add(s.charAt(y)); y++; if(y==s.length()){ y=0; } } }else{ BigInteger a = min.add(increment); BigInteger bigInteger=new BigInteger(String.valueOf(n)); // System.out.println("Output from else"); return a; } int a=0; //System.out.println("The list2 is: "+list); for(Character i:list){ if(i=='a'){ a++; } } BigInteger bigInteger=new BigInteger(String.valueOf(a)); return bigInteger; } public static void main(String[] args) { Scanner scanner=new Scanner(System.in); String repeatedString; long n; System.out.println("Enter your string: "); repeatedString=scanner.nextLine(); System.out.println("Enter your number: "); n=scanner.nextLong(); System.out.println(""+String.valueOf(repeat(repeatedString,n))); }} }
//}
Seems like cookies are disabled on this browser, please enable them to open this website
Repeated String
You are viewing a single comment's thread. Return to all comments →
This is my solution
package hackerrankcode;
import java.io.; import java.math.BigInteger; import java.util.;
public class Repeated_String {
//}