by printing the string line using printf the first line of the string will be aligned with the string line

Actually the first line is left aligned, but if you want the first line to be like the rest, as you wrote, you should change the format flag.

    String str = "canada";
    for (int i=0; i< str.length(); i++) {
        System.out.printf("%20s", str.substring(i) + "\n");

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top