第1个回答 2013-10-12
package mym3;
/*
* 用JAVA编写一个自动贩卖机的程序,要求提供咖啡,可乐和
* 茶,三种饮料。价格分别为2元,3元和5元。顾客选择自己想
* 要的东西后,投币,然后系统还要找补零钱。谢谢!
*/
import java.util.*;
public class crs {
public static void main(String[] agse) {
int a = 0, b = 0, c = 0, aa = 0;
Scanner input = new Scanner(System.in);
System.out.println("请选择物品的代号:1咖啡 2可乐 3茶");
String as = input.next();
if (as.equals("1")) {
System.out.println("你要买的是茶:2元");
a = 1;
} else if (as.equals("2")) {
System.out.println("你要买的是茶:3元");
b = 1;
} else if (as.equals("3")) {
System.out.println("你要买的是茶:5元");
c = 1;
} else {
System.out.println("你的输入有误!请重新输入!");
}
System.out.println("请支付现金:");
int as1 = input.nextInt();
if(as1>=2){
System.out.println("成了");
aa = as1 - 2;
}else if(as1>=3){
System.out.println("成了");
aa = as1 - 3;
}else if(as1>5){
System.out.println("成功");
aa = as1 -5;
}else{
System.out.println("你的钱不够");
}
if(aa==0){
System.out.println("你的钱刚好");
}else{
System.out.println("找你的钱为:"+aa);
}
}
}