1 今天写了学生类的程序
题目要求:
程序源代码:
package Student;
import java.util.Scanner;
public class Student {
public static void main(String[] args){
char[] s1 = {'2','0','1','9','0','3','2','7'};
char[] s2 = {'d','o','u','b','l','e','b','e','s','t'};
Student stu1 = new Student(s1,s2);
stu1.setAge(21);
stu1.show();
Student stu2 = new Student(stu1);
Scanner input = new Scanner(System.in);
String s = input.nextLine();
s1 = s.toCharArray();
s = input.nextLine();
s2 = s.toCharArray();
stu2.setNo(s1);
stu2.setName(s2);
stu2.show();
input.close();
}
static int sum = 0;
Student(char[] NO,char[] NAME){
int i=0;
no = NO;
name = NAME;
sum++;
System.out.println("Constructor run");
System.out.println("NumTotal:"+sum);
}
Student(char[] NO,char[] NAME,int AGE){
no = NO;
name = NAME;
age = AGE;
sum++;
System.out.println("Constructor run");
System.out.println("NumTotal:"+sum);
}
Student(Student S){
no = S.no;
name =S.name;
age = S.age;
sum++;
System.out.println("CopyConstructor run");
System.out.println("NumTotal:"+sum);
}
void setNo(char[] NO){no = NO;}
char[] getNo(){return no;}
void setName(char[] NAME){name = NAME;}
char[] getName(){return name;}
void setAge(int AGE){age = AGE;}
int getAge(){return age;}
void show(){
System.out.print("No:");
System.out.print(getNo());
System.out.print(",Name:");
System.out.print(getName());
System.out.println(",Age:"+age);
}
char[] no;
char[] name;
int age;
}
public static void main(String[] args){
char[] s1 = {'2','0','1','9','0','3','2','7'};
char[] s2 = {'d','o','u','b','l','e','b','e','s','t'};
Student stu1 = new Student(s1,s2);
stu1.setAge(21);
stu1.show();
Student stu2 = new Student(stu1);
Scanner input = new Scanner(System.in);
String s = input.nextLine();
s1 = s.toCharArray();
s = input.nextLine();
s2 = s.toCharArray();
stu2.setNo(s1);
stu2.setName(s2);
stu2.show();
input.close();
}
static int sum = 0;
Student(char[] NO,char[] NAME){
int i=0;
no = NO;
name = NAME;
sum++;
System.out.println("Constructor run");
System.out.println("NumTotal:"+sum);
}
Student(char[] NO,char[] NAME,int AGE){
no = NO;
name = NAME;
age = AGE;
sum++;
System.out.println("Constructor run");
System.out.println("NumTotal:"+sum);
}
Student(Student S){
no = S.no;
name =S.name;
age = S.age;
sum++;
System.out.println("CopyConstructor run");
System.out.println("NumTotal:"+sum);
}
void setNo(char[] NO){no = NO;}
char[] getNo(){return no;}
void setName(char[] NAME){name = NAME;}
char[] getName(){return name;}
void setAge(int AGE){age = AGE;}
int getAge(){return age;}
void show(){
System.out.print("No:");
System.out.print(getNo());
System.out.print(",Name:");
System.out.print(getName());
System.out.println(",Age:"+age);
}
char[] no;
char[] name;
int age;
}
运行截图:
2 今天知道了在java语言中没有指针的定义,但是在传参的时候可以传数组
3 明天继续写题