首页 技术 正文
技术 2022年11月23日
0 收藏 681 点赞 4,509 浏览 2366 个字

1.

public class ArrayRefDemo01{
public static void main(String args[]){
int temp[] = {1,3,5} ;// 利用静态初始化方式定义数组
fun(temp) ;// 传递数组
for(int i=0;i<temp.length;i++){
System.out.print(temp[i] + “、”) ;
}
}
public static void fun(int x[]){// 接收整型数组的引用
x[0] = 6 ;// 修改第一个元素
}
};

运行结果:

6、3、5、

2.

public class ArrayRefDemo02{
public static void main(String args[]){
int temp[] = fun() ;// 通过方法实例化数组
print(temp) ;// 打印数组内容
}
public static void print(int x[]){
for(int i=0;i<x.length;i++){
System.out.print(x[i] + “、”) ;
}
}
public static int[] fun(){// 返回一个数组
int ss[] = {1,3,5,7,9} ;// 定义一个数组
return ss ;
}
};

运行结果:

1,3,5,7,9

3.

public class ArrayRefDemo03{
public static void main(String args[]){
int score[] = {67,89,87,69,90,100,75,90} ;// 定义整型数组
int age[] = {31,30,18,17,8,9,1,39} ;// 定义整型数组
sort(score) ;// 数组排序
print(score) ;// 数组打印
System.out.println(“\n—————————“) ;
sort(age) ;// 数组排序
print(age) ;// 数组打印
}
public static void sort(int temp[]){// 执行排序操作
for(int i=1;i<temp.length;i++){
for(int j=0;j<temp.length;j++){
if(temp[i]<temp[j]){
int x = temp[i] ;
temp[i] = temp[j] ;
temp[j] = x ;
}
}
}
}
public static void print(int temp[]){// 输出数组内容
for(int i=0;i<temp.length;i++){
System.out.print(temp[i] + “\t”) ;
}
}
};

运行结果:

67 69 75 87 89 90 90 100
—————————
1891718303139

4.

public class ArrayRefDemo04{
public static void main(String args[]){
int score[] = {67,89,87,69,90,100,75,90} ;// 定义整型数组
int age[] = {31,30,18,17,8,9,1,39} ;// 定义整型数组
java.util.Arrays.sort(score) ;// 数组排序
print(score) ;// 数组打印
System.out.println(“\n—————————“) ;
java.util.Arrays.sort(age) ;// 数组排序
print(age) ;// 数组打印
}
public static void print(int temp[]){// 输出数组内容
for(int i=0;i<temp.length;i++){
System.out.print(temp[i] + “\t”) ;
}
}
};

运行结果:

67 69 75 87 89 90 90 100
—————————
1891718303139

5.

public class ArrayRefDemo05{
public static void main(String args[]){
int i1[] = {1,2,3,4,5,6,7,8,9} ;// 源数组
int i2[] = {11,22,33,44,55,66,77,88,99} ;// 目标数组
copy(i1,3,i2,1,3) ;// 调用拷贝方法
print(i2) ;
}
// 源数组名称,源数组开始点,目标数组名称,目标数组开始点,拷贝长度
public static void copy(int s[],int s1,int o[],int s2,int len){
for(int i=0;i<len;i++){
o[s2+i] = s[s1+i] ;// 进行拷贝操作
}
}
public static void print(int temp[]){// 输出数组内容
for(int i=0;i<temp.length;i++){
System.out.print(temp[i] + “\t”) ;
}
}
};

运行结果:

11 4 5 6 55 66 77 88 99

6.

public class ArrayRefDemo06{
public static void main(String args[]){
int i1[] = {1,2,3,4,5,6,7,8,9} ;// 源数组
int i2[] = {11,22,33,44,55,66,77,88,99} ;// 目标数组
System.arraycopy(i1,3,i2,1,3) ;// 调用Java中对数组支持的拷贝方法
print(i2) ;
}
public static void print(int temp[]){// 输出数组内容
for(int i=0;i<temp.length;i++){
System.out.print(temp[i] + “\t”) ;
}
}
};

运行结果:

11 4 5 6 55 66 77 88 99

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,992
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,506
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,767
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844