您的位置:首页 > 其它

今天我重拾书本,希望找回丢失的旧时光

2014-04-06 14:37 344 查看
Java语言程序设计, 第一页开始, 学习中

我甚至连最简单的都不明白

package home.gr;

import java.util.Scanner;

public class CakeSale {
public static void main(String args[])
{
float price;
float weight;
float sum;
price=50.0f;
System.out.println("原价:"+price+"元/磅");
System.out.print("\n 请输入冰激凌蛋糕的重量(磅):");
Scanner scanner=new Scanner(System.in);
weight=scanner.nextFloat();
if(weight>=2&&weight<3)
{
price=(float)(price*0.9);
System.out.print("\n输入重量为"+weight+"磅,能享受9折优惠,打折后价格:"+price+"元/磅");
}
else if(weight>=3)
{
price=(float)(price*0.8);
System.out.print("\n输入重量为"+weight+"磅,能享受8折优惠,打折后价格:"+price+"元/磅");
}
else
{
System.out.print("\n输入重量为"+weight+"磅,不能享受优惠。");
}
sum=price*weight;
System.out.println("\n应收金额为:"+sum+"元。");
}

}

Scanner  nextFloat
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: