Java前期总结小题目

        //逢7过
        for (int i = 0; i <= 1000; i++) {
            int g=i%10;
            int s=i/10%10;
            int b=i/100%10;
            if((i%7)!=0&&g!=7&&s!=7&&b!=7)
                System.out.println(i);
            else
                System.out.println("过");
        }

        //数组求和
        int array[]={68,27,95,88,171,996,51,210};
        int sum=0;
        for (int i = 0; i < array.length; i++) {
            int g=array[i]%10;
            int s=array[i]/10%10;
            if(g!=7&&s!=7&&array[i]%2==0) {
                System.out.println(array[i]);
                sum+=array[i];
            }
        }
        System.out.println(sum);
        //数组收尾交换

        //方法一
        int array[]=new int[]{19,28,37,46,50,19,19};

        for (int i = 0; i < array.length/2; i++) {
            int temp=array[i];
            array[i]=array[array.length-1-i];
            array[array.length-1-i]=temp;
        }
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }


        //方法二
        int array[]=new int[]{19,28,37,46,50,19,19};

        for (int i = 0,j=array.length-1; i < j; i++,j--) {
            int temp=array[i];
            array[i]=array[j];
            array[j]=temp;
        }
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
    //输出6个分数
    private static void scoreInput(int num,int arr[]) {
        Scanner sc=new Scanner(System.in);

        for (int i = 0; i < num; i++) {
            System.out.println("请输入分数:");
            arr[i]=sc.nextInt();
        }    
    }

    //查找最高分
    private static int maxFind(int[] arrayScore) {
        int max=arrayScore[0];
        for (int i = 0; i < arrayScore.length; i++) {
            if(arrayScore[i]>max)
            max= arrayScore[i];
        }
        System.out.println("最大值为"+max);
        return max;
    }

    //查找最低分
    private static int minFind(int[] arrayScore) {
        int min=arrayScore[0];
        for (int i = 0; i < arrayScore.length; i++) {
            if(arrayScore[i]<min)
                min= arrayScore[i];
        }
        System.out.println("最小值为"+min);
        return min;
    }

    //计算最终分值并输出
    private static void finalScore(int[] arrayScore, int max, int min) {
        int sum=0;
        for (int i = 0; i < arrayScore.length; i++) {
            sum+= arrayScore[i];
        }
        sum-= max + min;
        System.out.println("选手的成绩是"+sum);
    }


    public static void main(String[] args){

        int arrayScore[]=new int[6];
        scoreInput(6,arrayScore);
        for (int i = 0; i < arrayScore.length; i++) {
            System.out.println("第" + (i+1) + "个分数是:"+arrayScore[i]);
        }

        int max=maxFind(arrayScore);
        int min=minFind(arrayScore);
        finalScore(arrayScore, max, min);
   
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值