Java三次作业

已知每盒牛奶含有蛋白质 6.4g。编写一个程序,帮助用户根据购买牛奶的盒数计算蛋白质的含量。

import java.util.Scanner;

public class Milk {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入购买牛奶的盒数:");
        double a=sc.nextDouble();
        double b=6.4;
        System.out.println(a);
        System.out.println("每袋牛奶含有的蛋白质为:"+(a*b));
        sc.close();

    }

}

肯德基某连锁店光是汉堡就销售了5532个,假设每个汉堡的金额为15.5元,那么这些 汉堡一共卖了多少钱呢?请编写一个程序,帮助店员计算每天销售汉堡包的数量及金额

import java.util.Scanner;

public class KFC {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入售出汉堡的数量:");
        double c=sc.nextDouble();
        double d=15.5;
;        System.out.println(c);
        System.out.print("一天总售出的汉堡数量为:"+(c));
        System.out.println("个");
        System.out.print("全天售出的金额为:"+(c*d));
        System.out.println("元");
        sc.close();

    }

}

世界上第一条正式的高速铁路系统是1964年建成通车的日本新干线,设计速度200km/h, 所以高速铁路的初期速度标准就是200km/h。后来随着技术进步,高铁的速度越来越快。目 前我国运行中的高铁速度已经达到了350 公里/小时。请编写一个程序,将用户输入的高铁 速度km/h转换成m/s。

import java.util.Scanner;

public class Gaotie {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入速度:");
        double c=sc.nextDouble();
        double d=0.27;
        System.out.print(c);
        System.out.print("km/h=");
        System.out.print(c*d);
        System.out.print("m/s");
        sc.close();

        
    }

}

图8所示为某城市地铁2号线自动售票机售票的界面,到某站票价为2元,用户输入购 买票数后,可以看到应付金额和己付金额。编写一个程序,模拟实现地铁购票金额的计算, 输入效果如图9所示,输入票数后的程序输出结果如图10所示。

import java.util.Scanner;

public class Ditie {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        int a=2;
        System.out.println("购票信息");
        System.out.println("----------");
        System.out.println("目的车站:人民广场");
        System.out.println("票价:"+a+".00");
        System.out.println("购票数量:");
        int b=sc.nextInt();
        System.out.println("应付金额:"+(a*b));
        System.out.println("已付金额:");
        int c=sc.nextInt();
        System.out.println("找零:"+(c-(a*b)));
        sc.close();        
        
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值