Java编程题练习

这篇博客主要介绍了16个Java编程题目,涵盖了从基础到进阶的各类问题,旨在提升读者的Java编程技能。
摘要由CSDN通过智能技术生成

1.

package Test;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        System.out.println("请输入一个点的坐标:");
        Scanner sc = new Scanner(System.in);
        double x = sc.nextDouble();
        double y = sc.nextDouble();
        System.out.println(Pan(x,y));
    }

    public static boolean Pan(double a,double b){
        if (a <= 200 && b <= (-0.5 * a  + 100)){
            return true;
        }
        return false;
    }
}

/*
请输入一个点的坐标:
200 1
false
*/

2.

package Test;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        System.out.println("请输入第一个点的坐标以及矩形的宽高:");
        Scanner sc = new Scanner(System.in);
        double x1 = sc.nextDouble();
        double y1 = sc.nextDouble();
        double w1 = sc.nextDouble();
        double h1 = sc.nextDouble();
        System.out.println("请输入第二个点的坐标及矩形的宽高:");
        Scanner sc1 = new Scanner(System.in);
        double x2 = sc1.nextDouble();
        double y2 = sc1.nextDouble();
        double w2 = sc1.nextDouble();
        double h2 = sc1.nextDouble();

        double x = x1 -x2 >=0 ? x1-x2 : x2-x1;
        double y = y1-y2 >=0? y1-y2 : y2-y1;

        if (x <= (w1 - w2) / 2 && y <= (h1 - h2) / 2){
            System.out.println("r2 is inside r1");
        }
        else if (x<= (w1 + w2) / 2 && y <= (h1 + h2) / 2){
            System.out.println("r2 overlaps r1");
        }
        else {
            System.out.println("r2 does not overlap r1");
        }
    }
}

 3.

package Test;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        System.out.println("请输入第一个圆的中心和半径:");
        Scanner sc = new Scanner(System.in);
        double x1 = sc.nextDouble();
        double y1 = sc.nextDouble();
        double b1 = sc.nextDouble();
        System.out.println("请输入第二个圆的中心和半径:");
        Scanner sc1 = new Scanner(System.in);
        double x2 = sc1.nextDouble();
        double y2 = sc1.nextDouble();
        double b2 = sc1.nextDouble();

        if (Math.sqrt((x1 - x2) +(y1 - y2)) <= Math.abs(b1 - b2)){
            System.out.println("圆二在圆一内");
        }
        else if (Math.sqrt((x1 - x2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值