1,计算牛奶中蛋白质的总量
![](https://i-blog.csdnimg.cn/blog_migrate/2dc3433109f30c9fd24e9e187e4f5271.png)
package danbai;
import java.util.Scanner;
public class danbaiz {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入购买牛奶的盒数:");
float a = 6.4f;
Scanner scanner=new Scanner(System.in);
int b = scanner.nextInt();
System.out.println("含有蛋白质"+a*b);
scanner.close();
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/dac2598bf89bd55a7eb1c57a9e74ce20.png)
运行结果
2, 输出肯德基一天售出汉堡的数量及金额
![](https://i-blog.csdnimg.cn/blog_migrate/16eae3f990707123e85d03f64cc9532b.png)
package kdj;
import java.util.Scanner;
public class kkj {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入售出的汉堡数量:");
float a = 15.5f;
Scanner scanner=new Scanner(System.in);
System.out.println("每个汉堡金额为"+a);
float b=15.5f;
System.out.println("一天总出售汉堡数量为:");
try (Scanner scanner1 = new Scanner(System.in)) {
int c=scanner1.nextInt();
System.out.println("全天售出的总金额"+b*c);
}
scanner.close();
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/3c89bce67dc796f781f17ce1167e50cb.png)
运行结果
3,将高铁速度km/h转换为m/s
![](https://i-blog.csdnimg.cn/blog_migrate/4d81daeee9180cdb23d3faf9d86e141e.png)
package ketang28;
import java.util.Scanner;
public class ketanglx28 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入速度km/h:");
float a=3.6f;
Scanner scanner=new Scanner(System.in);
float b=scanner.nextInt();
System.out.print("km/h=:"+Math.floor(b/a));
System.out.print("m/s");
scanner.close();
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/038a0cfa4947d9ede18c8141b64a105d.png)
运行结果
四,地铁购票金额计算
![](https://i-blog.csdnimg.cn/blog_migrate/99380b56fcdbae0bbf272cf4563ae04a.png)
package ditie;
import java.util.Scanner;
public class dit {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("购票信息");
System.out.println("==============");
System.out.println("目的地:"+"人民广场");
System.out.println("票价:"+2.00);
int a=2;
System.out.println("购票数量:");
Scanner scanner=new Scanner(System.in);
int b=scanner.nextInt();
System.out.println("应付金额:"+a*b);
System.out.println("已付金额:");
int c=scanner.nextInt();
int d=c-a*b;
System.out.println("已付金额:"+c);
System.out.println("找零"+d);
scanner.close();
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/e3f547f6a80c34f4d73fe6cdd5ad8c11.png)
运行结果