吉软-人文精英班-第三次作业

1、利用方法重载,写三个方法,分别求出int类型绝对值,float类型绝对值double类型绝对值
 

public class ChongZai {
	public static int zhanHuan(int n)//重载int
	{
		if(n<0)//判断
			n*=-1;
		return n;
	}
	public static float zhanHuan(float n)//重载float
	{
		if(n<0)
			n*=-1;
		return n;
	}
	public static double zhanHuan(double n)//重载double
	{
		if(n<0)
			n*=-1;
		return n;
	}
	public static void main(String[] args) {
		System.out.println(zhanHuan(-1));
		System.out.println(zhanHuan(-1f));
		System.out.println(zhanHuan(-1.0));
	}
}

2、将下面给定的数组转置输出
   例如   原数组: 1,2,3,4,5,6
    转置之后的数组: 6,5,4,3,2,1

public class ZhanZhi{
	public static int[] zhanZhi(int[] a)
	{
		int k=a.length;//获组长
		int[] b=new int[k];
		for(int i=0;i<k;i++)
		{
			b[i]=a[k-1-i];//转置
		}
		return b;
	}
	public static void main(String[] args) {
		int[] a= {1,2,3,4,5,6};
		a=zhanZhi(a);
		for(int i=0;i<a.length;i++)
		{
			System.out.print(a[i]);//输出
		}
	}
}

4、现在有如下2个数组
 数组A: “1,7,5,7,9,2,21,13,45”
 数组B:  “2,5,8,14,21”
将俩个数组合并为数组C,按顺序排列输出

public class Copy {
	public static void main(String[] args) {
		int[] a= {1,7,5,7,9,2,21,13,45};
		int[] b= {2,5,8,14,21};
		int c=a.length+b.length;//声明并定义数组d
		int[] d=new int[c];
		System.arraycopy(a, 0, d, 0, a.length);//copy数组a
		System.arraycopy(b, 0, d, a.length, b.length);//copy数组b
		for(int i=0;i<c;i++)
		{
			System.out.print(d[i]+" ");
		}
	}
}

 

转载于:https://my.oschina.net/u/3858170/blog/1815094

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值