Neil_UK
3
Q:

The purpose of this exercise is to test your understanding of formatting output using printf.

public static void main(String args[]){
    Scanner scanner =  new Scanner(System.in);

    for (int i=0;i<2;i++){
       String string = scanner.next();
       int num = scanner.nextInt();


       System.out.printf("%-14s %03d %n", string, num);       //note the use of printf
       // %-14s  fifteen characters left-justified o to 14
       // %03d padded with leading zero

    }
}
0

New to Communities?

Join the community