Menu
Topics Index
...
`

Currency2922


If you need explanation Read this topic

If you need Answer Take test on this topic

Currency2922
What will be output of the following program?
import java.util.*;

public class DifferentCurrency {
    public static void main(String[] args) {
        printCurrency(Locale.US);
        printCurrency(Locale.TAIWAN);
        printCurrency(Locale.ITALY);
    }
    public static void printCurrency(Locale locale) {
        Currency c;
        c = Currency.getInstance(locale);
        System.out.println(c.getCurrencyCode());
    }
}

A. USD
TWD
EUR
B. US
TAIWAN
ITALY
C. Some other output
D. Compilation Error or Runtime Error
Topic: Java Currency Class

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ns is A.. here we have the Locale class which represents the represents a specific geographical, cultural Region..here we have the some constants in the Locale class...US which represents the country..here we have 2more constants...

here are receiving the with locale class reference...

getInstance() this method takes the input as the Locale object and returns the Currency class returns Object related to the Locale Objects...

next we are calling getCurrencyCode() which will returns the Currency code of the Particular Cuntry...

here Us---USD
TAIWAN--TWD
ITA:Y--EUR

Posted by Uday Kumar    2014-12-03 12:38:46


ans a.

public final class Currency
extends Object
implements Serializable

Represents a currency. Currencies are identified by their ISO 4217 currency codes. Visit the ISO web site for more information, including a table of currency codes.
The class is designed so that there's never more than one Currency instance for any given currency. Therefore, there's no public constructor. You obtain a Currency instance using the getInstance methods.

Locale class object represents a specific geographical, political, or cultural region. .Following are the important points about Locale:

--An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to form information for the user.

--Locale is a mechanism for identifying objects, not a container for the objects themselves.

The java.util.Currency.getInstance() method returns the Currency instance for the given locale's country.

getCurrencyCode() method gets the ISO 4217 currency code of the currency.

comint to this program printcurrency method called  with constant country values.
getInstance method returns the ocale's country.

sop prints country's code of the currency

Posted by Maheshwari Natarajan    2014-12-03 13:31:10


This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Uday Kumar, Maheshwari Natarajan,  for 'Best Comment' and Uday Kumar for the 'Popular Comment'. The 'lucky liker' is Uday Kumar. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-12-05 05:12:30


© meritcampus 2019

All Rights Reserved.

Open In App