Reordering output with argument indices. - Java Language Basics

Java examples for Language Basics:Number Format

Description

Reordering output with argument indices.

Demo Code

public class Main 
{
   public static void main(String[] args) 
   {/*w  ww.  ja  v a 2  s . c o m*/
      System.out.printf(
         "Parameter list without reordering: %s %s %s %s\n", 
         "first", "second", "third", "fourth");
      System.out.printf(
         "Parameter list after reordering: %4$s %3$s %2$s %1$s\n", 
         "first", "second", "third", "fourth");      
   } 
}

Result


Related Tutorials