第六次作业--static关键字、对象

##题目一

##Computer

package Train.Method.TeachDemo.Thread.Fuction;

/**
 * 求n的阶乘算法 
 * @author 喵
 * @date 2019年9月18日下午1:19:34
 */
public class Computer {
    public int num;

    public Computer() {
    }

    public Computer(int num) {
        this.num = num;
    }

    public long counter() {
        long sum = 1;
        for (int i = 1; i <= num; i++) {
            sum = sum * i;
        }
        return sum;
    }
}

##Test

package Train.Method.TeachDemo.Thread.FuctionTest;
import Train.Method.TeachDemo.Thread.Fuction.Computer;

import java.util.Scanner;

import Train.Method.TeachDemo.Thread.Fuction.Computer;
/**
 * Test
 * @author 喵
 * @date 2019年9月18日下午8:08:53
 */
public class ComputerTest {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入一个整数:");
        int num = input.nextInt();
        
        Computer t = new Computer(num);
        System.out.println(t.counter());
    }
} 

##题目二

##MyPoint

/**
 * 坐标类
 * 
 * @author 喵
 * @date 2019年9月18日下午8:12:32
 */
public class MyPoint {
    private int x;
    private int y;

    public MyPoint() {

    }

    public MyPoint(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public static double distance(MyPoint p1, MyPoint p2) {
        int xside = Math.abs(p1.x - p2.x);
        int yside = Math.abs(p1.y - p2.y);
        double temp = Math.pow(xside, 2) + Math.pow(yside, 2);
        return (Math.sqrt(temp));
    }
}

##Test

import java.util.Scanner;

/**
 * 测试点距离类
 * @author 喵
 * @date 2019年9月18日下午3:53:51
 */
public class Test {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入p1点的坐标");
        int x1 = input.nextInt();
        int y1 = input.nextInt();
        System.out.println("请输入p2点的坐标");
        int x2 = input.nextInt();
        int y2 = input.nextInt();
        
        MyPoint p1 = new MyPoint(x1, y1);
        MyPoint p2 = new MyPoint(x2, y2);
        System.out.println("两点之间的距离为;" + MyPoint.distance(p1, p2));
    }
}

猜你喜欢

转载自www.cnblogs.com/CatMiao1176/p/11545110.html