标签:format mat 算法 equal ble The ack rgs void
package The_Forty_first; import java.util.Scanner; //任务一:求两坐标直线距离的关键算法(30分) //输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。输入数据有多组,每组占一行,由4个实数组成, //分别表示x1,y1,x2,y2,数据之间用空格隔开。 //例如输入: 1 3 4 6 则输出:4.24 //注意:对于每组输入数据,输出一行,结果保留两位小数 public class one { public static void main(String[] args) { test(); } private static void test() { System.out.println("请输入数据:"); Scanner scanner = new Scanner(System.in); int x1 = scanner.nextInt(); int y1 = scanner.nextInt(); int x2 = scanner.nextInt(); int y2 = scanner.nextInt(); double distance = Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow(y2 - y1, 2)); String s = String.format("%.2f",distance);//%.2f自动四舍五入 System.out.println(s); System.out.println("请输入是否继续!y or 任意键结束!"); String str = scanner.next(); if (str.equals("y")) { test(); } } }
标签:format mat 算法 equal ble The ack rgs void
原文地址:https://www.cnblogs.com/chenjiajiale/p/12862623.html