Formatting output with class Formatter. - Java Language Basics

Java examples for Language Basics:Number Format

Description

Formatting output with class Formatter.

Demo Code

import java.util.Formatter;
import javax.swing.JOptionPane;

public class Main 
{
   public static void main(String[] args) 
   {//from   ww w. j ava  2  s. co  m
      // create Formatter and format output
      Formatter formatter = new Formatter();
      formatter.format("%d = %#o = %#X", 10, 10, 10);

      // display output in JOptionPane
      JOptionPane.showMessageDialog(null, formatter.toString());
   } 
}

Related Tutorials