def run( self ) : #--------------------------------------------------------------------------- # Name: label() # Role: Instantiate a Right aligned label with the specified text #--------------------------------------------------------------------------- def label( text ) : return JLabel( text + ' ', horizontalAlignment = SwingConstants.RIGHT ) frame = JFrame( 'PropertyListener', layout = BorderLayout(), locationRelativeTo = None, size = ( 400, 300 ), defaultCloseOperation = JFrame.EXIT_ON_CLOSE ) pane = JPanel( layout = GridLayout( 0, 2 ) ) pane.add( label( 'Number:' ) ) pane.add( JFormattedTextField( NumberFormat.getNumberInstance(), value = 12345.67890, columns = 10, propertyChange = self.changed ) ) pane.add( label( 'Currency:' ) ) pane.add( JFormattedTextField( NumberFormat.getCurrencyInstance(), value = 12345.67890, columns = 10, propertyChange = self.changed ) ) frame.add( JSplitPane( JSplitPane.HORIZONTAL_SPLIT, pane, JButton( 'Clear', actionPerformed = self.clear ), ), BorderLayout.NORTH ) self.textArea = JTextArea( rows = 10, columns = 40, editable = 0, focusable = 0, font = Font( 'Courier' , Font.BOLD, 12 ) ) frame.add( JScrollPane( self.textArea ), BorderLayout.CENTER ) frame.setVisible( 1 )
import java.util.*; import java.text.*; import java.util.Scanner; import java.text.NumberFormat; import java.util.Locale; public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double payment = scanner.nextDouble(); scanner.close(); Locale indiaLocale = new Locale("en", "IN"); NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US); NumberFormat india = NumberFormat.getCurrencyInstance(indiaLocale); NumberFormat china = NumberFormat.getCurrencyInstance(Locale.CHINA); NumberFormat france = NumberFormat.getCurrencyInstance(Locale.FRANCE); System.out.println("US: " + us.format(payment)); System.out.println("India: " + india.format(payment)); System.out.println("China: " + china.format(payment)); System.out.println("France: " + france.format(payment)); } }