Java控制语句习题02

在这里插入图片描述

public static void main(String[] args) {
	/*1.让用户输入一组坐标
	 * 计算坐标到圆心的距离
	 * 判断小于10或等于是在圆内,否则在圆外
	 * */
	Scanner scanner=new Scanner(System.in);
	System.out.println("please enter a point");
	int x=scanner.nextInt();
	int y=scanner.nextInt();
	double dis=Math.pow(Math.pow(x, 2)+Math.pow(y, 2), 0.5);
	if(dis<10||dis==10) {
		System.out.println("point("+x+","+y+")is in the circle");
	}else {
		System.out.println("point("+x+","+y+")is not in the circle");
	}
}

在这里插入图片描述

public static void main(String[] args) {
	/*让用户输入两个圆的坐标 和半径
	 * 计算两个圆心之间的距离
	 * 判断
	 * 	距离大于半径之和两圆不接触
	 * 	距离小于两圆半径之和但是大于半径之差的绝对值就是重叠
	 * 	距离小于半径之差的绝对值就是包含
	 * 
	 * */
	Scanner scanner=new Scanner(System.in);
	System.out.println("please enter two two points ofcirclr and two radius");
	double x1=scanner.nextDouble();
	double y1=scanner.nextDouble();
	double x2=scanner.nextDouble();
	double y2=scanner.nextDouble();
	double r1=scanner.nextDouble();
	double r2=scanner.nextDouble();
	double dis=Math.pow(Math.pow(x1-x2, 2)+Math.pow(y1-y2, 2), 0.5);
	if(dis>r1+r2) {
		System.out.println("两个圆不接触");
	}else if(dis<r1+r2&&dis>Math.abs(r1-r2)) {
		System.out.println("两个圆重叠");
	}else {
		System.out.println("包含关系");
	}
}

在这里插入图片描述

public static void main(String[] args) {
	/*让用户不断输入数字,输入0时结束 
	 * 输入数字后判断正负
	 * 将数字加起来计算总和还有平均值
	 * */
	Scanner scanner=new Scanner(System.in);
	System.out.println("please enter some number");
	int sum=0;//总和
	double ave=0;//平均
	int po=0;//正数
	int ne=0;//负数
	int n=0;//总共次数
	do {
		int x=scanner.nextInt();
		n++;
		sum=sum+x;
		ave=sum/n;
		if(x>0) {
			po++;
		}else if(x<0) {
			ne++;
		}else{
			break;
		}
	}while(true);
	System.out.println("the number of positives is "+po);
	System.out.println("the number of negatives is "+ne);
	System.out.println("the total is "+sum);
	System.out.println("the average is "+ave);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值