Right justifying and left justifying values - Java Language Basics

Java examples for Language Basics:Number Format

Description

Right justifying and left justifying values

Demo Code

public class Main 
{
   public static void main(String[] args)
   { /*  w  w  w  .  j  av  a  2  s.co  m*/
      System.out.println("Columns:");
      System.out.println("0123456789012345678901234567890123456789\n");
      System.out.printf("%10s%10d%10c%10f\n\n", "hello", 7, 'a', 1.23);
      System.out.printf(
         "%-10s%-10d%-10c%-10f\n", "hello", 7, 'a', 1.23);
   } 
}

Related Tutorials