这是我应该得到的。
样本输出:带有x和y坐标的计算区域,如何在x和y中打破一组数字?
Please enter the coordinates in a clockwise order.
Enter the GPS coordinates for the 1st city: 35.2270869 -80.8431267
Enter the GPS coordinates for the 2nd city: 32.0835407 -81.0998342
Enter the GPS coordinates for the 3rd city: 28.5383355 -81.3792365
Enter the GPS coordinates for the 4th city: 33.7489954 -84.3879824
The area is: 117863.342
import java.util.Scanner;
public class problem {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please enter the coordinates in a clowise order");
System.out.println("Enter the GPS coordinates for the 1st city: ");
double coordinateOne= input.nextInt();
System.out.println("Enter the GPS coordinates for the 1st city: ");
double coordinateTwo= input.nextInt();
System.out.println("Enter the GPS coordinates for the 1st city: ");
double coordinateThree= input.nextInt();
System.out.println("Enter the GPS coordinates for the 1st city: ");
double coordinateFour= input.nextInt();
double earthRadius= 6371.01;
//Get distance
//distance=(radius)arccos(sin(x1)sin(x2)+cos(x1)cos(x2)cos(y1−y2))
double distance= (earthRadius)*Math.acos(Math.sin(coordinateOne)*Math.sin(coordinateTwo))
+ Math.cos(coordinateOne)*Math.cos(coordinateTwo);
// System.out.println("The area is: "+distance);
}
}
我有,例如,如果我进入35.2270869 -80.8431267
麻烦,我如何将它们分开来x
和y
?
我必须使用短语:
Enter the GPS coordinates for the # city.
我需要它,以便分离,以它们(x
和y
)传递给该公式。
如果他们输入'35.2270869 80.8431267'而不是... – MadProgrammer 2014-10-27 05:39:33
您可以使用空格字符作为split()方法的分隔符。我认为SPACE字符是split()分隔符的最好的字符。 – 2014-10-27 05:41:40
@MadProgrammer答案更简单。 :) – 2014-10-27 05:42:27