第二次考核

 

码云: https://gitee.com/gs717/codes

 

第一题  7.5  

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
                Scanner in = new Scanner(System.in);
                int[] grade = new int[5];
                for(int i=0; i<grade.length; i++){
                      grade[i] = in.nextInt();
                 }      
 
                RR rr = new RT(grade);
                double dd = rr.mark();
                System.out.printf("%.2f",dd);
    }
}
abstract class RR{
   int[] grade;
   public RR(int[] grade){
      this.grade = grade;
   }
   public abstract double mark();
}
class RT extends RR{
 
 
}
7.6  集体评分 
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
                Scanner in = new Scanner(System.in);
                int[] grade = new int[5];
                for(int i=0; i<grade.length; i++){
                      grade[i] = in.nextInt();
                 }      
 
                RR rr = new RT(grade);
                double dd = rr.mark();
                System.out.printf("%.2f",dd);
    }
}
abstract class RR{
   int[] grade;
   public RR(int[] grade){
      this.grade = grade;
   }
   public abstract double mark();
}
class RT extends RR{
 
}
 
 
 
7.7  程序填空
 
 
public class Main {
    public static void main(String[] args) {
        Son son = new Son();
        son.method();
    }
}
class Parent {
    Parent() {
        System.out.println("Parent's Constructor without parameter");
    }
    Parent(boolean b) {
        System.out.println("Parent's Constructor with a boolean parameter");
    }
    public void method() {
        System.out.println("Parent's method()");
    }
}
class Son extends Parent {
    Son() {
        super(true);    //调用父类有参构造 ()内true或false都可以
        System.out.println("Son's Constructor without parameter");
    }
    public void method() {
        System.out.println("Son's method()");
        super.method();
    }
}
 
 
7.8 

两点距离:代码如下

package testprograme;
 
import java.util.Scanner;
 
public class xy {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
        String inputString = sc.nextLine();
        String stringArray[] = inputString.split(" ");
        int num[] = new int[stringArray.length];
        for (int i = 0; i < stringArray.length; i++) {
              num[i] = Integer.parseInt(stringArray[i]);
              System.out.println(num[i]);
        }
        int xAll = Math.abs(num[0]) + Math.abs(num[2]);
        int yAll = Math.abs(num[1]) + Math.abs(num[3]);
        double lineLength = Math.pow(xAll,2) + Math.pow(yAll,2);
        double cLength = Math.pow(lineLength, 1.0/2);
        System.out.println(cLength);
}
}

利用个 数学公式求两点间距离因为是象限 输入值可能为负数所以运用了绝对值

a^+b^=c^ 输出c^后开放  即为所求结果

 

 
 
 
posted @ 2018-10-13 19:25  郜硕  阅读(184)  评论(1编辑  收藏  举报