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

0

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

    }
}
Posted by: Guest on October-19-2020

Code answers related to "The purpose of this exercise is to test your understanding of formatting output using printf."

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language