Anonymous

# 請問一下這樣的程式碼有錯嗎

//********************************************************************

// 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);

}

}

Rating
• ?
Lv 6

最後兩句都忘了加 + 了。。。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);     }}