Trending News
請問一下這樣的程式碼有錯嗎
因為是要求兩點的距離,可是最後四行執行不出來,想請問一下哪裡有問題??
//********************************************************************
// point.java Author: noname
//
// Demonstrates the use of the Math class to perform a calculation
// based on user input.
//********************************************************************
import java.util.Scanner;
public class point
{
public static void main (String[] args)
{
int x1,x2,y1,y2;
double unit,p1,p2;
Scanner scan=new Scanner (System.in);
System.out.print("Enter the x-axis of first point :");
x1=scan.nextInt();
System.out.print("Enter the y-axis of first point :");
y1=scan.nextInt();
System.out.print("Enter the x-axis of second point :");
x2=scan.nextInt();
System.out.print("Enter the y-axis of second point :");
y2=scan.nextInt();
p1=Math.pow((x2-x1),2);
p2=Math.pow((y2-y1),2);
unit=Math.sqrt(p1 p2);
System.out.println("distance:" unit);
}
}
1 Answer
- ?Lv 62 decades agoFavorite Answer
最後兩句都忘了加 + 了。。。import java.util.Scanner;public class Point { public static void main (String[] args) { int x1,x2,y1,y2; double unit,p1,p2; Scanner scan=new Scanner (System.in); System.out.print("Enter the x-axis of first point :"); x1=scan.nextInt(); System.out.print("Enter the y-axis of first point :"); y1=scan.nextInt(); System.out.print("Enter the x-axis of second point :"); x2=scan.nextInt(); System.out.print("Enter the y-axis of second point :"); y2=scan.nextInt(); p1=Math.pow((x2-x1),2); p2=Math.pow((y2-y1),2); unit=Math.sqrt(p1 + p2); System.out.println("distance:" + unit); }}
Source(s): http://caterpillar.onlyfun.net/