I need to right justify the next output using Java:
class MyTree {
public static void staircase(int n) {
String myGraph = "#";
for(int i=0; i<n; i++){
for(int x = 0; x <=i; x++){
if(x == i){
System.out.printf("%s\n", myGraph);
}else{
System.out.printf("%s", myGraph);
}
}
}
}
}
I'm using printf function but I'm stuck, I tried different parameters but nothing seems to work; in case you have a suggestion please let me know.
Thanks
You can't right justify unless you know the 'length' of a line, and there's no way to know that. Not all things
System.outcan be connected to have such a concept.If you know beforehand, you can use
%80sfor example. If you don't, what you want is impossible.