帮我看一下错误~~

来源:百度知道 编辑:UC知道 时间:2024/09/28 09:41:52
import java.lang.Math;
import java.util.Scanner;
public class Distance1 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter the x and y coordinates of the first point (separated by a comma): ");
String firstPoint = sc.next();
int p = firstPoint.indexOf(",");
double x1 = firstPoint.substring(0,p);
double y1 = firstPoint.substring(p,p+1);

Scanner sb = new Scanner(System.in);
System.out.print("Enter the x and y coordinates of the second point (separated by a comma): ");
String secondPoint = sb.next();
double q = secondPoint.indexOf(",");
double x2 = secondPoint.substring(0,q);
double y2 = secondPoint.substring(q,q+1);

double distance = Math.sqrt(Math.pow(x2,2) - Math.pow(x1,2) + Math.pow(y2,2) - Math.pow(y1,2));
System.out.println("The First Point is:" + "

可以用string的split函数
他可以帮你根据,将字符串分解为两个字符串,然后你就得到两个数了,然后转换为整数就行了.

那你中间用什么格开...?计算机如何判断一个数

譬如132464567461321如何来判断这俩数都是几....

具体的话
int p = firstPoint.indexOf(",");

你想用什么格开俩数 ,那么就把","换成什么吧