Java,第一次作业——货币兑换

题目:

( 金融:货币兑换)编写一个程序,提示用户输入从美元到人民币的兑换汇率。提示用
户输入 0 表示从美元兑换为人民币,输入 1 表示从人民币兑换为美元。继而提示用户输
入美元数量或者人民币数量,分别兑换为另外一种货币。下面是运行示例
在这里插入图片描述

class Tang_01_20
{
	public static void main(String[] args)
	{
		 Scanner input=new Scanner(System.in);
		 System.out.print("Enter the exchange rate from dollars to RMB:  ");
		 double rate=input.nextDouble();
		 System.out.print("Enter 0 to convert dollars to RMB and 1 vice versa:  ");
		 int choice=input.nextInt();
		switch(choice)
		 {
			 case 0:
			  System.out.print("Enter dollar amount:  ");
			   int amount=input.nextInt();
			    System.out.println("$"+amount+"is"+ amount*6.81+" Yuan ");
				break;
				 case 1:
			  System.out.print("Enter the RMB amount:  ");
			   int amount_1=input.nextInt();
			    System.out.println(amount_1+"Yuan is $"+(amount_1/6.81) );
				break;
				default:
				System.out.println("Incorrect input");
				break;
		 }
	}
}

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值