第六次作业 20194698

题目一

computer类

package aa;
public class computer {    
        static int sum=1;//sum赋值为1
        public static int chengjie(int n){
            //for循环进行阶乘运算
        for(int i=1;i<=n;i++) {
            sum*=i;
        }
        return sum;//返回sum值
        }
    }

App.java

package ojbk;
import java.util.Scanner;

import aa.computer;
public class xfx {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner a=new Scanner(System.in);//创建对象
System.out.println("输入乘阶数");
int c=a.nextInt();
computer s=new computer();//创建对象s
System.out.println("阶乘结果:"+s.chengjie(c));//打印computer类中阶乘结果
}

}

 题目二

package ojbk1;

public class MyPoint {//创建MyPoint累
    double x;//设置变量x,y
    double y;
    public double getX() {//成员x访问器
        return x;
    }
    public void setX(double x) {//成员x修改器
        this.x = x;
    }
    public double getY() {//成员x访问器
        return y;
    }
    public void setY(double y) {//成员x修改器
        this.y = y;
    }
    MyPoint(){//创建无参构造方法
        x=0;
        y=0;
    }
    MyPoint(double x,double y){//创建有参构造方法
        this.x = x;
        this.y = y;
    }
    static double distance(MyPoint p1,MyPoint p2) {
        double m=Math.sqrt((p1.x - p2.x)*(p1.x - p2.x)+(p1.y - p2.y)*(p1.y - p2.y));//求两点间距离
        return m;//返回m值
    }
}
package ojbk1;

import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner reader=new Scanner(System.in);
        System.out.println("输入点p1的横纵坐标:");
        double a=reader.nextInt();//键盘输入
        double b=reader.nextInt();//键盘输入
        System.out.println("输入点p2的横纵坐标:");
        double c=reader.nextInt();//键盘输入
        double d=reader.nextInt();//键盘输入
        MyPoint p1=new MyPoint(a,b);//创建对象p1
        MyPoint p2=new MyPoint(c,d);//创建对象p2
        double m=MyPoint.distance(p1, p2);
        System.out.println(m);//打印m
    }

}

猜你喜欢

转载自www.cnblogs.com/zdxxx/p/11552296.html