程福健-20194666—第六次作业

 1  /*编写一个computer类包含***** 求n的阶乘的方法*/
 2 app.java
 3 
 4 package com.yao.test;
 5 import com.yao.test.Computer;
 6 public class app {
 7         public static void main(String[] args) {
 8             // TODO Auto-generated method stub
 9             Computer computer = new Computer();//创建一个对象
10             int total = computer.getFac(3);// 将传参过去的值的运算结果赋值给 total变量
11             System.out.println(total);//进行输出
12         }
13 }
 1 Computer.java
 2 
 3 package com.yao.test;
 4 
 5 public class Computer {
 6         public static void main(String[] args) {
 7             // TODO Auto-generated method stub
 8         }
 9         public static int getFac(int n) {//创建一个静态类,对传参传过来的值进行阶层的运算
10             if(n == 1|| n==0)
11                 return 1;
12             else
13                 return n*getFac(n-1);
14         }
15     
16 }

程福健-20194666—第六次作业_第1张图片

 

 

 

 1 Spit_SL.java
 2 
 3 /*设计一个MyPoint类 计算 x和y的坐标距离*/
 4 
 5 package com.yao.test;
 6 import java.util.*;
 7 class Mypoint{ //创建一个坐标类  包含三个变量
 8     double x,y;//  横坐标及竖坐标
 9     Point p2;// 定义一个点 p2
10     protected Mypoint(double a, double b){//进行传参赋值
11         x = a;
12         y = b;
13     }
14     Mypoint(){//定义一个内部类 给p2坐标赋值
15         p2 = new Point(0, 0);
16     }
17     static double distance(Mypoint p1,Mypoint p2){ //定一个内部类 进行坐标距离的运算
18         return (Math.sqrt(Math.abs((p1.getX() - p2.getX())* (p1.getX() - p2.getX())+(p1.getY() - p2.getY())* (p1.getY() - p2.getY()))));
19     }
20     public double getX() { //取出当前坐标的 x位置
21         // TODO Auto-generated method stub
22         return x;
23     }
24     public double getY() {//取出当前坐标的 y的位置
25         // TODO Auto-generated method stub
26         return y;
27     }
28 }
29 
30 public class Spit_SL {
31     public static void main(String[] args) {
32         
33         Mypoint p1 = new Mypoint(1,1);//给p1坐标 赋值横竖坐标 
34         Mypoint p2 = new Mypoint(5,8);//给p2坐标 赋值横竖坐标 
35         double distance = Mypoint.distance(p1,p2);// 创建一个对象 把赋值过的俩个坐标点传参给 Mypoint类  并把结果赋值给 distance这个变量
36         System.out.print(+distance);//输出
37     }
38 }

程福健-20194666—第六次作业_第2张图片

 

你可能感兴趣的:(程福健-20194666—第六次作业)