2018.5.17 作业

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


public class ChongZai {

    public static void main(String[] args) {

        int a=jueDui(-8);
        float b=jueDui(-6);
        double c=jueDui(-7);
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
    }
    public static int jueDui(int a) {
        if(a>=0) {
            a=a;
        }
        else {
            a=-a;
        }
        return a;
    }
    public static float jueDui(float a) {
        if(a>=0) {
            a=a;
        }
        else {
            a=-a;
        }
        return a;
    }
    public static double jueDui(double a) {
        if(a>=0) {
            a=a;
        }
        else {
            a=-a;
        }
        return a;
    }

}
210131_aqq7_3858480.png

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


public class ZhuanZhi {

    public static void main(String[] args) {
        int a[]= {1,2,3,4,5,6};
        for(int i=5;i>=0;i--) {
            System.out.print(a[i]+" ");
        }
    }

}
210421_YtZ4_3858480.png

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


public class HeBing {

    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[]=new int[a.length+b.length];
        System.arraycopy(a, 0, c, 0, a.length);  
        System.arraycopy(b, 0, c, a.length, b.length); 
        for(int i=0;i<c.length;i++) {
            System.out.print(c[i]+" ");
        }
        System.out.println();
        for(int k=1;k<c.length;k++) {
            for(int j=0;j<c.length-k;j++) {
                if(c[j]>c[j+1]) {
                    int t=c[j];
                    c[j]=c[j+1];
                    c[j+1]=t;
                }
            }
        }
        for(int i=0;i<c.length;i++) {
            System.out.print(c[i]+" ");
        }
    }

}

 

211209_HF1y_3858480.png
 

 

 

转载于:https://my.oschina.net/u/3858480/blog/1814458

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值