zoukankan      html  css  js  c++  java
  • Java学习第39天2020/8/13

    一.
    import java.util.Scanner; public class point { Scanner input=new Scanner(System.in); private double x,y,z; public void in() { x=input.nextDouble();y=input.nextDouble();z=input.nextDouble(); } public void out(){ System.out.println("("+x+","+y+","+z+")"); } public void get() { System.out.println("x="+x+" "+"y="+y+" "+"z="+z+" "); } public void distance() { double p=x*x+y*y+z*z; System.out.println("到原点的距离是:"+Math.sqrt(p)); } public static void main(String []args) { point m=new point(); m.in(); m.out(); m.get(); m.distance(); } }

     

    math.sqrt(double n);//其中n是被开方的数

    如要给m开n次方就用:
    java.lang.StrictMath.pow(m,1.0/n);

    import java.util.Scanner;
    public class point extends line{
    	Scanner input=new Scanner(System.in);
    	private double x,y,z;
    	public void in()
    	{
    		x=input.nextDouble();y=input.nextDouble();z=input.nextDouble();
    	}
    	public void out(){
    		System.out.println("("+x+","+y+","+z+")");
    	}
    	public double get_x()
    	{
    		return x;
    	}
    	public double get_y()
    	{
    		return y;
    	}
    	public double get_z()
    	{
    		return z;
    	}
    	public void distance()
    	{
    		double p=x*x+y*y+z*z;
    		System.out.println("到原点的距离是:"+Math.sqrt(p));
    	}
    	
    	}



    public class line {
        public static void main(String []args) {
            point []a=new point[2];
            System.out.println("输入两点的坐标:");
            for(int i=0;i<2;i++)
            {
                a[i]=new point();
            }
            for(int i=0;i<2;i++) {
            a[i].in();}
            double l=Math.pow(a[0].get_x()-a[1].get_x(), 2)+Math.pow(a[0].get_y()-a[1].get_y(), 2)+Math.pow(a[0].get_z()-a[1].get_z(), 2);
            System.out.println("两点之间的距离为:"+Math.sqrt(l));
            }
    }

     二.math.pow(x,2)

     math.sqrt(l);

    三.例题

  • 相关阅读:
    童年
    转:如何破解超星打印页数限制
    2016.7.14.2014noip模拟赛D1(网上貌似搜不到
    商店购物
    几道有趣的题
    2016.7.11.第27套测试题(noip2013提D1)
    2016.7.12.第28套测试题(2013noip题D2)
    跨域访问http接口的使用
    心得之——程序的修改和拓展
    不使用<script>导入js文件
  • 原文地址:https://www.cnblogs.com/qiangini/p/13498745.html
Copyright © 2011-2022 走看看