Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
java-exercise
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
时良荣
java-exercise
Commits
7786caa7
Commit
7786caa7
authored
Sep 28, 2020
by
时良荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
彭晖=Java培训-数组
parent
03a2e4ba
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
144 additions
and
0 deletions
+144
-0
ExerciseFifth.java
src/main/java/com/exercise/eighth/ExerciseFifth.java
+41
-0
ExerciseFirst.java
src/main/java/com/exercise/eighth/ExerciseFirst.java
+17
-0
ExerciseFourth.java
src/main/java/com/exercise/eighth/ExerciseFourth.java
+23
-0
ExerciseSecond.java
src/main/java/com/exercise/eighth/ExerciseSecond.java
+15
-0
ExerciseThird.java
src/main/java/com/exercise/eighth/ExerciseThird.java
+48
-0
ExerciseFifth.class
target/classes/com/exercise/eighth/ExerciseFifth.class
+0
-0
ExerciseFirst.class
target/classes/com/exercise/eighth/ExerciseFirst.class
+0
-0
ExerciseFourth.class
target/classes/com/exercise/eighth/ExerciseFourth.class
+0
-0
ExerciseSecond.class
target/classes/com/exercise/eighth/ExerciseSecond.class
+0
-0
ExerciseThird.class
target/classes/com/exercise/eighth/ExerciseThird.class
+0
-0
No files found.
src/main/java/com/exercise/eighth/ExerciseFifth.java
0 → 100644
View file @
7786caa7
package
com
.
exercise
.
eighth
;
import
java.util.Arrays
;
/**
* 4.写一段代码,实现System.arraycopy方法的功能
* @author elliot
*/
public
class
ExerciseFifth
{
public
static
void
main
(
String
[]
args
)
{
int
[]
nums
=
{
1
,
2
,
3
,
4
,
5
,
6
};
int
[]
newNums
=
new
int
[
10
];
arraycopy
(
nums
,
1
,
newNums
,
2
,
3
);
System
.
out
.
println
(
Arrays
.
toString
(
newNums
));
}
private
static
void
arraycopy
(
Object
[]
src
,
int
srcPos
,
Object
[]
dest
,
int
destPos
,
int
length
)
{
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
dest
[
destPos
++]
=
src
[
srcPos
++];
}
}
private
static
void
arraycopy
(
float
[]
src
,
int
srcPos
,
float
[]
dest
,
int
destPos
,
int
length
)
{
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
dest
[
destPos
++]
=
src
[
srcPos
++];
}
}
private
static
void
arraycopy
(
double
[]
src
,
int
srcPos
,
double
[]
dest
,
int
destPos
,
int
length
)
{
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
dest
[
destPos
++]
=
src
[
srcPos
++];
}
}
private
static
void
arraycopy
(
int
[]
src
,
int
srcPos
,
int
[]
dest
,
int
destPos
,
int
length
)
{
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
dest
[
destPos
++]
=
src
[
srcPos
++];
}
}
}
src/main/java/com/exercise/eighth/ExerciseFirst.java
0 → 100644
View file @
7786caa7
package
com
.
exercise
.
eighth
;
/**
* 彭晖=Java培训-数组
* .定义一个数组,其中元素为公司的一级部门名称,按照【下标:值】
* 格式打印出来。
* 如:0:xxx, 1:xxx, 2:xxx
* @author elliot
*/
public
class
ExerciseFirst
{
public
static
void
main
(
String
[]
args
)
{
String
[]
company
=
{
"内部服务中心"
,
"客户成功中心"
,
"市场中心"
,
"技术中心"
,
"产品中心"
};
for
(
int
i
=
0
;
i
<
company
.
length
;
i
++){
System
.
out
.
println
(
i
+
":"
+
company
[
i
]);
}
}
}
src/main/java/com/exercise/eighth/ExerciseFourth.java
0 → 100644
View file @
7786caa7
package
com
.
exercise
.
eighth
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 统计数组【1,5,6,12,1,32,5,6】中每个元素出现的次数
* @author elliot
*/
public
class
ExerciseFourth
{
public
static
void
main
(
String
[]
args
)
{
int
[]
nums
=
{
1
,
5
,
6
,
12
,
1
,
32
,
5
,
6
};
System
.
out
.
println
(
counter
(
nums
).
toString
());
}
private
static
Map
<
Integer
,
Integer
>
counter
(
int
[]
array
)
{
Map
<
Integer
,
Integer
>
map
=
new
HashMap
<>();
for
(
int
element:
array
)
{
map
.
put
(
element
,
map
.
getOrDefault
(
element
,
0
)
+
1
);
}
return
map
;
}
}
src/main/java/com/exercise/eighth/ExerciseSecond.java
0 → 100644
View file @
7786caa7
package
com
.
exercise
.
eighth
;
import
java.util.Arrays
;
/**
* 将int数组【99、23、34、67、123、234、1、98】按照升序排列
* @author elliot
*/
public
class
ExerciseSecond
{
public
static
void
main
(
String
[]
args
)
{
int
[]
nums
=
{
99
,
23
,
34
,
67
,
123
,
234
,
1
,
98
};
Arrays
.
sort
(
nums
);
System
.
out
.
println
(
Arrays
.
toString
(
nums
));
}
}
src/main/java/com/exercise/eighth/ExerciseThird.java
0 → 100644
View file @
7786caa7
package
com
.
exercise
.
eighth
;
import
java.util.*
;
/**
* 去掉数组【1、2、3、4、2、2、1、5、6】中的重复元素
* @author elliot
*/
public
class
ExerciseThird
{
public
static
void
main
(
String
[]
args
)
{
int
[]
nums
=
{
1
,
2
,
3
,
4
,
2
,
2
,
1
,
5
,
6
};
int
[]
news
=
intsUnique
(
nums
);
System
.
out
.
println
(
Arrays
.
toString
(
news
));;
}
/**
* int[] 数组去重
* @param arr
* @return
*/
public
static
int
[]
intsUnique
(
int
[]
arr
){
int
[]
news
=
new
int
[
getNoRepeatNum
(
arr
)];
int
index
=
0
;
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
if
(
Arrays
.
binarySearch
(
news
,
arr
[
i
])
<
0
){
news
[
index
]
=
arr
[
i
];
index
++;
}
}
return
news
;
}
/**
* 去重后的元素个数
* @param ints
* @return
*/
public
static
int
getNoRepeatNum
(
int
[]
ints
)
{
List
list
=
new
ArrayList
();
for
(
int
i
=
0
;
i
<
ints
.
length
;
i
++){
if
(!
list
.
contains
(
ints
[
i
])){
list
.
add
(
ints
[
i
]);
}
}
return
list
.
size
();
}
}
target/classes/com/exercise/eighth/ExerciseFifth.class
0 → 100644
View file @
7786caa7
File added
target/classes/com/exercise/eighth/ExerciseFirst.class
0 → 100644
View file @
7786caa7
File added
target/classes/com/exercise/eighth/ExerciseFourth.class
0 → 100644
View file @
7786caa7
File added
target/classes/com/exercise/eighth/ExerciseSecond.class
0 → 100644
View file @
7786caa7
File added
target/classes/com/exercise/eighth/ExerciseThird.class
0 → 100644
View file @
7786caa7
File added
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment