標題:
TQC+ 104 距離計算
[打印本頁]
作者:
周政輝
時間:
2016-12-10 11:23
標題:
TQC+ 104 距離計算
[attach]1816[/attach]
作者:
王彥甯
時間:
2016-12-10 11:32
本帖最後由 王彥甯 於 2016-12-10 11:40 編輯
import java.util.Scanner;
public class JPA01 {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
System.out.print("輸入第一組X和Y座標:");
float x1 = scanner.nextFloat();
float y1 = scanner.nextFloat();
System.out.print("輸入第二組X和Y座標:");
float x2 = scanner.nextFloat();
float y2 = scanner.nextFloat();
float result = (float)(Math.pow(x2-x1, 2)+Math.pow(y2-y1, 2));
float distance = (float) Math.sqrt(result);
System.out.printf("介於(%.2f , %.2f)和(%.2f , %.2f)之間的距離是%.2f",x1,y1,x2,y2,distance);
}
}
複製代碼
作者:
蔡庭豪
時間:
2016-12-10 11:53
import java.util.Scanner;
public class JPA01 {
public static void main(String args[]){
Scanner scanner =new Scanner(System.in);
System.out.println("詩入第1組的x和y的座標");
float x1 = scanner.nextFloat();
float y1 = scanner.nextFloat();
System.out.println("詩入第2組的x和y的座標");
float x2 = scanner.nextFloat();
float y2 = scanner.nextFloat();
float xfar =x1-x2;
float yfar =y1-y2;
double far1 =Math.pow(xfar, 2)+Math.pow(yfar, 2) ;
double far2=Math.sqrt(far1);
System.out.printf("介於(%.2f,%.2f)和(%.2f,%.2f)之間的距離是%.2f",x1,y1,x2,y2,far2);
}
}
複製代碼
作者:
張健勳
時間:
2016-12-10 11:55
import java.util.Scanner;
public class JPA01 {
public static void main (String args[]){
Scanner scanner = new Scanner(System.in);
System.out.print("請輸入第一組 x 和 y 座標");
double x1 = scanner.nextDouble();
double y1 = scanner.nextDouble();
System.out.print("請輸入第二組 x 和 y 座標");
double x2= scanner.nextDouble();
double y2= scanner.nextDouble();
float dis = (float)(Math.pow(x2-y2,2)+Math.pow(x1-y1,2));
dis = (float)Math.sqrt(dis);
System.out.printf("介於 (%.2f , %.2f) 和 (&.2f , &.2f) 之間的距離是 &.2f",x1,x2,y1,y2,dis);
}
}
複製代碼
作者:
蔡季樺
時間:
2016-12-16 18:48
import java.util.Scanner;
public class JPA01
{
public static void main(String args[])
{
Scanner scanner = new Scanner(System.in);
System.out.print("輸入第一組的X和Y座標:");
float x = scanner.nextFloat();
float y = scanner.nextFloat();
System.out.print("輸入第二組的X和Y座標:");
float x2 = scanner.nextFloat();
float y2 = scanner.nextFloat();
float result = (float)(Math.pow(x2-x, 2)+Math.pow(y2-y, 2));
float distance = (float) Math.sqrt(result);
System.out.printf("介於(%.2f , %.2f)和(%.2f , %.2f)之間的距離是%.2f",x,y,x2,y2,distance);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2