Skip to content

Commit bd9c9af

Browse files
committed
g
1 parent a4edc6e commit bd9c9af

7 files changed

Lines changed: 187 additions & 53 deletions

File tree

JavaTest/.idea/workspace.xml

Lines changed: 104 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 Bytes
Binary file not shown.
934 Bytes
Binary file not shown.
1.16 KB
Binary file not shown.
680 Bytes
Binary file not shown.

JavaTest/src/DumplicatArray.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
public class DumplicatArray {
2+
3+
4+
public static void main(String args[]){
5+
int[] number=new int[0];
6+
int[] fa={0};
7+
duplicate(number,number.length,fa);
8+
System.out.println(fa[0]);
9+
}
10+
// Parameters:
11+
// numbers: an array of integers
12+
// length: the length of array numbers
13+
// duplication: (Output) the duplicated number in the array number,length of duplication array is 1,so using duplication[0] = ? in implementation;
14+
// Here duplication like pointor in C/C++, duplication[0] equal *duplication in C/C++
15+
// 这里要特别注意~返回任意重复的一个,赋值duplication[0]
16+
// Return value: true if the input is valid, and there are some duplications in the array number
17+
// otherwise false
18+
public static boolean duplicate(int numbers[],int length,int [] duplication) {
19+
if(numbers.length==0){
20+
return false;
21+
}
22+
int[] num=new int[numbers.length];
23+
for(int i=0;i<numbers.length;i++){
24+
num[numbers[i]]++;
25+
}
26+
for(int j=0;j<num.length;j++){
27+
if(num[j]>1){
28+
duplication[0]=j;
29+
return true;
30+
}
31+
}
32+
return false;
33+
}
34+
35+
}

JavaTest/src/TestArray.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
public class TestArray {
2+
3+
public static void main(String[]args ){
4+
Person Lee=new Person("Lee",20);
5+
Person Mary=new Person("Mary",18);
6+
Person[] Students=new Person[2];
7+
Students[0]=Lee;
8+
Students[1]=Mary;
9+
Students[0].setName("piopi");
10+
Lee.getInfo();
11+
Mary.getInfo();
12+
Students[0].getInfo();
13+
Students[1].getInfo();
14+
15+
16+
17+
}
18+
19+
20+
21+
}
22+
class Person{
23+
private String name;
24+
private int age;
25+
26+
public Person(String name,int age){
27+
this.age=age;
28+
this.name=name;
29+
}
30+
public String getName() {
31+
return name;
32+
}
33+
34+
public int getAge() {
35+
return age;
36+
}
37+
38+
public void setName(String name) {
39+
this.name = name;
40+
}
41+
42+
public void setAge(int age) {
43+
this.age = age;
44+
}
45+
public void getInfo(){
46+
System.out.println("age:"+this.getAge()+" name:"+this.getName());
47+
}
48+
}

0 commit comments

Comments
 (0)