I can't seem to understand the following code, especially the if statement. Could anyone help me out. Thank You.
public void printTriangle(String input) {
String tmp = input.substring(1);
StringBuilder builder = new StringBuilder(tmp);
builder = builder.reverse().append(input);
String line = builder.toString();
for(int i = 0; i < input.length(); i++){
for(int j = 0; j < line.length(); j++){
if(i + 1 == input.length() || Math.abs(j - line.length()/2) == i){
System.out.print(line.charAt(j));
}else{
System.out.print(" ");
}
}
System.out.println();
}
}}
Aucun commentaire:
Enregistrer un commentaire