标签:view int https parameter form http 没有 double bool
码云:https://gitee.com/lishaoyu123/codes/nky8rceip1q0vd5w2xs6436
程序设计思路:创建一个有关人Person的类,实例化类构造函数,进行调用
知识点:创建类,有参函数与无参函数的构造,调用
以上内容为考试时自己编写,在与同学总结查看之后得到答案如下:
1 import java.util.Scanner;
2
3 class Person{
4 private String name = null;
5 private int age = 0;
6 private boolean gender = false;
7 private int id = 0;
8
9 public Person() {
10 System.out.println("This is constructor");
11 System.out.println(name+","+age+","+gender+","+id);
12 System.out.println("Person [name="+name+", age="+age+", gender="+gender+", id="+id+"]");
13 }
14
15 public Person(String n, int a, boolean g) {
16 this.name = n;
17 this.age = a;
18 this.gender = g;
19 }
20
21 public String toString() {
22 System.out.println("Person [name="+this.name+", age="+this.age+", gender="+this.gender+", id="+0+"]");
23 return name;
24 }
25 }
26
27 public class Main {
28
29 public static void main(String[] args) {
30 Scanner reader = new Scanner(System.in);
31 int number = reader.nextInt();
32 Person[] per = new Person[number]; //初始化对象数组
33 for(int i=0; i<per.length; i++) { //通过循环从键盘输入
34 String name = reader.next();
35 int age = reader.nextInt();
36 boolean genter = reader.nextBoolean();
37 per[i] = new Person(name,age,genter);
38 }
39 for(int x=per.length-1; x>=0;x--){ //通过循环从后往前输出
40 per[x].toString();
41 }
42
43 per.toString();
44 Person s = new Person();
45 }
46
47 }

22 class RT extends RR{
23 RT(int[] grade){
24 super(grade);
25 }
26 public double mark(){
27 Arrays.sort(grade); //将数组 升序排序
28 return (double)(grade[1]+grade[2]+grade[3])/3; //求平均值
29 }
30 }

程序思路:对父类进行调用,注意顺序,在考试时没有考虑到super()的用法,须写在子类构造函数的第一句
知识点:参数传值
class Son extends Parent {
void Parent(){
System.out.println("Son‘s Constructor without parameter");
}
public void method() {
System.out.println("Son‘s method()");
}
class Son extends Parent {
Son() {
super(true); //调用父类有参构造
System.out.println("Son‘s Constructor without parameter");
}
public void method() {
System.out.println("Son‘s method()");
super.method();
}
运行结果:

import java.util.*;
import java.math.*;
public class Main{
public static void main (String[] args){
Scanner input = new Scanner(System.in);
double x1 = input.nextDouble();
double y1 = input.nextDouble();
double x2 = input.nextDouble();
double y2 = input.nextDouble();
System.out.println(String.format("%.2f",Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))));
}
}
运行结果:

总结:我有好好学习JAVA语言,上课听讲,不玩手机!
| 学习内容 | 代码行数 | 博客字数 |
| 构造方法 | 53 | 150 |
| 子类与父类 | 50 | 60 |
| 第二次作业 | 30 | 700 |
运行结果:
标签:view int https parameter form http 没有 double bool
原文地址:https://www.cnblogs.com/lsylsy/p/9787982.html