java两点距离_我想计算Java中两点之间的距离

该Java程序旨在获取用户输入的两个圆的中心坐标和半径,然后计算并判断两圆是否相交。在计算两点距离时,出现了类型转换问题,Eclipse提示将距离解析为数组。代码中使用Math.sqrt()计算距离,但未正确处理乘法操作,导致错误。
摘要由CSDN通过智能技术生成

好的,所以我写了一个程序,让我可以确定两个圆圈是否重叠。

除了一个问题,我的程序无任何问题:程序将不接受我为两个中心点之间的距离编写的代码。我可以弄清楚if / else的逻辑来告诉用户,随后的距离值会发生什么,但是我想知道现在出了什么问题。 Eclipse,我正在编码的程序,告诉我,距离应该被解析成一个数组,但是我已经告诉过你这是一个int。

这是我的代码:

package circles;

import java.util.Scanner;

public class MathCircles {

// variable for the distance between the circles' centers

public static int distance;

// variable for the lengths of the radii combined

public static int radii;

public static void main(String[] args) {

// Get the x-value of the center of circle one

System.out.println("What is the x-coordinate for the center of circle one?");

Scanner keyboard = new Scanner(System.in);

int x1 = keyboard.nextInt();

//Get the y-value of the center of circle one

System.out.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值