I'm solving a problem in Java and it works perfectly in Netbeans without any error message but the website's compiler where I upload my code drops me the following error:
Compile error: Main.java:16: error: cannot find symbol
String finalString = newString.repeat(n + 1);
^
symbol: method repeat(int)
location: variable newString of type String
My code:
Scanner sc = new Scanner(System.in);
String myString = sc.nextLine();
int n = sc.nextInt();
String finalString = "";
for (int i = 0; i < myString.length(); i++) {
String newString = myString.substring(n + 1, myString.length());
finalString = newString.repeat(n + 1);
}
System.out.println(finalString);
}
}
Sample input:
Hello
2
Sample output:
lololo