快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

人名币符号java代码 人名币符号java代码是多少

java怎么输出货币符号

public static void main(String... args) {

成都创新互联公司专注于企业成都全网营销推广、网站重做改版、银川网站定制设计、自适应品牌网站建设、H5页面制作电子商务商城网站建设、集团公司官网建设、成都外贸网站建设公司、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为银川等各大城市提供网站开发制作服务。

// 人民币¥符号。

System.out.println(Currency.getInstance("CNY").getSymbol(Locale.CHINA));

// 台币NT$符号。  

System.out.println(Currency.getInstance("TWD").getSymbol(Locale.TAIWAN));

// 美金$符号。 

System.out.println(Currency.getInstance("USD").getSymbol(Locale.US));    

}

java string.format 如何转换人民币符号¥

一般用Format的子类来实现这个功能的:DecimalFormat

DecimalFormat df=new DecimalFormat("###,###.##¥");

//#表示数字。这个模式代表 整数部分每三位会有一个,隔开 小数部分四舍五入为2位。

//¥的位置可以任意更改

System.out.println(df.format(1231.12));

java程序。 输入为CNY USD等货币缩写。 输出为 ¥ $等 该货币的符号。currency类

因为我们用的都是中文环境(默认),所以你的程序只能输入中国的货币符号,要通过Locale类的: public static void setDefault(Locale newLocale)方法设置下语言环境

具体代码可参考如下的:

import java.util.Currency;

import java.util.Locale;

import java.util.Scanner;

/**

*

* @author top

*/

public class CurrencySymbol {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

System.out.println("Please input a valid ISO 4217 currency code: ");

Scanner scan = new Scanner(System.in);

String code1 = scan.nextLine();

Locale.setDefault(Locale.CHINA);//中文语言环境下

Currency currency1 = Currency.getInstance(code1);

System.out.println(currency1.getSymbol());

String code2 = scan.nextLine();

Locale.setDefault(Locale.US);//美国

Currency currency2 = Currency.getInstance(code2);

System.out.println(currency2.getSymbol());

}

}

用java编写一个程序,可实现人民币,美元,日元,欧元,台币,港币之间的任意转换

package Test;

import javax.swing.JOptionPane;

public class Test2 {

public static void main(String[] args) {

int numOf10=0;

int numOf5=0;

int numOf1=0;

int numOf0_5=0;

int numOf0_1=0;

Double money=Double.parseDouble(JOptionPane.showInputDialog("输入money"));

int total=(int)(money*10);

while(total0){

if((total-100)=0){

total-=100;

numOf10++;

}else if((total-50)=0){

total-=50;

numOf5++;

}else if((total-10)=0){  

total-=10;  

numOf1++;

}else if((total-5)=0){ 

total-=5;  

numOf0_5++;

}else if((total-1)=0){

total-=1;    

numOf0_1++;

}

}

if(numOf10!=0){

System.out.println("10元人民币:"+numOf10+"张");

}

if(numOf5!=0){

System.out.println("5元人民币:"+numOf5+"张");

}

if(numOf1!=0){

System.out.println("1元人民币:"+numOf1+"张");

}

if(numOf0_5!=0){

System.out.println("5角人民币:"+numOf0_5+"张");

}

if(numOf0_1!=0){

System.out.println("1角人民币:"+numOf0_1+"张");

}

}

}

下面哪些标识符在java语言中是合法的

//合法标识符,首位不能是数字;

//Java关键字不能当作Java标识符;

//标识符不能包含空格;

//不能包含@、#等其他特殊字符,只能包含美元符号($);

包名:字母全部小写。如,com.abc.dollapp。

常量名:采用大写形式,单词之间以下划线“_”隔开。

标识符组成

Java标识符由数字,字母和下划线(_),美元符号($)或人民币符号(¥)组成。在Java中是区分大小写的,而且还要求首位不能是数字。最重要的是,Java关键字不能当作Java标识符。

下面的标识符是合法的:

myName,My_name,Points,$points,_sys_ta,OK,_23b,_3_

下面的标识符是非法的:

#name,25name,class,time,if

以上内容参考;百度百科-java标识符

Java定义一个表示人民币的类Money,

public class Money {

private int yuan;

private int jiao;

private int fen;

public Money(int yuan,int jiao, int fen){

this.yuan=yuan;

this.jiao=jiao;

this.fen=fen;

}

public void show(){

System.out.printf("%d元%d角%d分",yuan,jiao,fen);

}

public static void main(String[] args) {

Money m=new Money(4,5,6);

m.show();

}

}


文章名称:人名币符号java代码 人名币符号java代码是多少
标题路径:http://6mz.cn/article/hpshdj.html

其他资讯