0

パラメータの国を持つメソッドがあります。このパラメータには、国の略語のみが含まれます。メソッドでは、スイッチケースなどを使用せずに国のフルネームを出力したいが、事前定義された文字列を使用する

final String VA="Vatikan";
String country="VA";
system.out.println(country);
//Is it possible that it Prints Vatikan now?
//I know not with that code but is there a possibillity to do that.
4

3 に答える 3

6

いいえ。ただし、マップを使用して目的の結果を達成することはできます。具体的には、省略された国名の完全な名前を返すには:

String va="Vatikan";
String country="VA";
Map<String, String> abbreviationMap = new HashMap<String, String>();
abbreviationMap.put(country, va);
System.out.println(abbreviationMap.get(country)); //prints "Vatikan"
于 2013-02-15T00:46:13.557 に答える
1

これにより、適切に割り当てられます。

final String VA="Vatikan";
String country=VA;
System.out.println(country);

String 変数countryは、変数が指しているものが何であれVA指されます。VA変更できないので (それはですfinal)、country は「Vatikan」を指します。

于 2013-02-15T00:45:14.593 に答える
0

国にを割り当てることですがstring "VA"、それをとして扱いたいvariableので、を削除しquotes("")ます。

final String VA="Vatikan";
String country=VA;
System.out.println(country);
于 2013-02-15T00:52:44.567 に答える