The method is the following:
public static long repeatedString(String s, long n) {
int convertedLong = (int) n;
String repeated = new String(new char[convertedLong]).replace("\0", s);
System.out.println(repeated);
long numberOfAs = 0;
for (int i = 0; i < convertedLong; i++ )
{
if (repeated.charAt(i) == 'a')
{
numberOfAs += 1;
}
}
System.out.print(numberOfAs);
return numberOfAs;
}
method works fine when the parameter n
is small, however when it is large like 1000000000000
it throws an exception:
The literal 1000000000000 of type int is out of range