In ' '*(r-x-1) and '*'*(2*x+1), you used multiplication of strings, which python supports but java does not. The problem can be solved by writing a loop which adds to the string on every iteration.
String r=""; //creating a String variable to store the string to be printed
for (int i=1; i<=(r-x-1); ++i) { //loop will repeat (r-x-1) times
r=r+" "; //adding ' ' to r every time the loop runs
}
for (int i=1; i<=(2*x+1) { //loop will run (2*x+1) times
r=r+"*"; //adding '*' to r every time the loop runs
}
System.out.println(r); //printing r
Hope this helps. :) Lemme know if this solved your problem, k?