求空间两点距离

使用说明

输入形式: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;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值