PrintfExamples.java Source code

Java tutorial

Introduction

Here is the source code for PrintfExamples.java

Source

public class PrintfExamples {
    public static void main(String[] args) {

        String[] words = new String[] { "a", "ape", "asdfasdfasdfasdfasdfasdfasdfadsfasdf" };
        System.out.printf("%-10s %s\n", "Word", "Length");
        for (String word : words)
            System.out.printf("%-10.10s %s\n", word, word.length());

    }

}
/*
Word       Length
a          1
ape        3
asdfasdfas 36
*/