使用说明
输入形式:1,1,1 2,2,2
源码留念
package Math.exersise114;
import java.util.Calendar;
import java.util.Scanner;
public class App {
private static String typing = null;
private static int[] c1 = null;
private static int[] c2 = null;
private static double result = 0;
private static Scanner scanner = new Scanner(System.in);
private static String msg = null;
public static void main(String[] args) {
for (;;) {
try {
start();
} catch (Exception e) {
// TODO: handle exception
msg = "error typing!";
display();
}
}
}
private static void start() {
// TODO Auto-generated method stub
input();
conv();
cal();
display();
}
private static void input() {
// TODO Auto-generated method stub
msg = "input coordinate or opreation code";
display();
if (scanner.hasNextLine()) {
typing = scanner.nextLine();
}
}
private static void conv() {
// TODO Auto-generated method stub
if (typing.equals("c")) {
exit();
}
String str[] = typing.split(" ");
String c1Str[] = str[0].split("\\,");
String c2Str[] = str[1].split("\\,");
c1 = new int[3];
c2 = new int[3];
for (int i = 0; i < 3; i++) {
c1[i] = Integer.parseInt(c1Str[i]);
c2[i] = Integer.parseInt(c2Str[i]);
}
}
private static void exit() {
// TODO Auto-generated method stub
msg = "exit procedure!";
display();
System.exit(0);
}
private static void display() {
// TODO Auto-generated method stub
System.out.println(msg);
}
private static void cal() {
int a = c1[0] - c2[0];
int b = c1[1] - c2[1];
int c = c1[2] - c2[2];
result = Math.sqrt(a * a + b * b + c * c);
msg = "the result=" + result;
}
}