Java第十四次作业

题目一:计算加速度

package java第十四次作业;

public class one {
	public static void main(String [] args) {//主函数
		double t=15.5;//定义时间为t
		int x=1050;//定义滑行距离设置为x
		double a;//定义加速度为a
		a=(2*x)/(Math.sqrt(t));//用Math方法调用sqrt
		System.out.println("加速度为"+a);//输出语句输出计算后的加速度
	}

}

题目二: 卖苹果的四舍五入

package java第十四次作业;
import java.util.Scanner;//创建Scanner
public class two {

	public static void main(String[] args) {//主函数
		double hqw;//定义购买斤数
		System.out.println("苹果售价:2.49元RMB/斤");//输出语句
		Scanner sc=new Scanner(System.in);//创建Scanner获取键盘上的数
		System.out.println("输入顾客购买苹果的重量(斤)");//输出语句提示
		double a =sc.nextDouble();//把获取到的数给a
		hqw=a*2.49;//计算价格
		System.out.println("顾客购买苹果的总价为:"+Math.round(hqw)+"RMB");//输出购买的价格
		System.out.println("顾客y应付金额为:"+Math.round(hqw)+"RMB");//输出应付的金额

	}

}

题目三:使用Math.min()判断坐标轴上两个点离原点哪个近

package java第十四次作业;

public class three {

	public static void main(String[] args) {
		System.out.println("利用横坐标与纵坐标差比较距离");//因为这里是B点再前
		double b=Math.min(Math.abs(Math.sqrt(3.8)+Math.abs(Math.sqrt(4.2))),Math.abs(Math.sqrt(3.2)+Math.abs(Math.sqrt(4.5))));//定义min值
		double t=Math.abs(Math.sqrt(3.8)+Math.abs(Math.sqrt(4.2)));//t为B点坐标
		double d=Math.abs(Math.sqrt(3.2)+Math.abs(Math.sqrt(4.5)));//d为C点坐标
		
		if(t>b) {//判断与最小值大小
			System.out.println("离A点更近的是C点");//输出语句
		}
		else {//反之
			System.out.println("离A点更近的是B点");//输出语句
		}
		
	}

}

 

 题目四:七星彩票(简易)

package java第十四次作业;
import java.util.Scanner;
public class four {

	public static void main(String[] args) {//主函数
		
		Scanner sc=new Scanner(System.in);//创建Scanner入口从键盘上赋值
		System.out.println("请输入您购买的彩票数:");
		int a=sc.nextInt();//把赋给的值给a
		
		int bb=a*2;//计算票价然后把结果给bb
		System.out.println("您购买的彩票号码如下:");//输出语句
		int iNum2=(int)((Math.random()*9+1)*1000000);//用Math.random随机产生数为开奖号
		for(int i = 1;i<=a;i++) {//开始循环随机数
		int	iNum=(int)((Math.random()*9+1)*1000000);//用Math.random随机产生数为彩票号
		int a1[]= {iNum};//把每随机出来的数赋值给a1数组
		
		for(int b = 0;b<a1.length;b++) {//遍历数组输出随机结果
			
		
			System.out.println(a1[b]);//输出语句
			if(a1[b]==iNum2) {//判断开奖是否与你买的相等
				
			     int num=0;//初始化num值
				int fw =num+ 5;//若中奖就加5元
			   
		}}}
		
		int fw=0;//初始化fw值
		System.out.println("您购买的彩票号码是:"+a+",共消费:"+bb+"元");//输出语句
		System.out.println("本期开奖号"+iNum2);//输出语句
		System.out.println("您赢得了"+fw+"元!");//输出语句
		System.out.println("您中奖的总金额:"+fw+"元!");}//输出语句
		
			
		
	}

		
		
		
		

	


		
				
			   
				
				
				

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

遇見即是上上籤

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值