96/97/98.JAVA入门__查找、反转、评委打分

查找

package com.itheima;
import java.util.Scanner;
public class ninety_six {
public static void main(String[] args) {
System.out.println(“请输入一个数字:”);
Scanner sc = new Scanner (System.in);
int a = sc.nextInt();
int dex = -1;
int[] arr = {19,28,37,46,50};
for(int i=0;i<arr.length;i++){
if(a == arr[i]) {
dex = i;
}
}
System.out.println(dex);
}
}

用方法:

package com.itheima;
import java.util.Scanner;
public class ninety_six {
public static void main(String[] args) {
System.out.println(“请输入一个数字:”);
Scanner sc = new Scanner (System.in);
int a = sc.nextInt();
System.out.println(getNumber(a));
/* int dex = -1;
int[] arr = {19,28,37,46,50};
for(int i=0;i<arr.length;i++){
if(a == arr[i]) {
dex = i;
}
}
System.out.println(dex);*/

}

public static int getNumber(int a){
    int[] arr = {19,28,37,46,50};
    int index = -1;
    for(int i=0;i<arr.length;i++){
        if(a == arr[i]){
            index = i;
            break;
        }
    }
    return index;

}

}

反转

package com.itheima;

public class niniety_seven {
public static void main(String[] args) {

    int[] arr = {19,28,37,46,50};
    int[] brr = {50,46,37,28,19};
    System.out.print("arr=");
    appear(arr);
    System.out.print("brr=");
    appear(brr);
    reverse(arr,brr);
    System.out.println("交换后的结果为:");
    System.out.print("arr=");
    appear(arr);
    System.out.print("brr=");
    appear(brr);
}

public static void reverse(int[] arr,int[] brr){
    int temp;
    for(int i=0;i<arr.length;i++){
        temp = arr[i];
        arr[i] = brr[i];
        brr[i] = temp;
    }

}


public static void appear(int[] arr){
    System.out.print("{");
    for(int i=0;i<arr.length;i++){
        System.out.print(arr[i]+",");
    }
    System.out.println("}");

}

}

评委打分

package com.itheima;

import java.util.Scanner;

public class ninety_eight {
public static void main(String[] args) {
int[] arr = new int[6];
for(int i=0;i<arr.length;i++){
Scanner sc = new Scanner(System.in);
System.out.println(“请输入第”+ (i+1) +“评委的评分:”);
arr[i] = sc.nextInt();
}
appear(arr);
int max = maxScore(arr);
int min = minScore(arr);
int sum = sum(arr);
System.out.println(“平均分为:”+ (sum-min-max)/(arr.length-2));
}

public static void appear(int[] arr){
    System.out.print("得分为:{");
    for(int i=0;i<arr.length;i++){
        if(i == arr.length-1){
            System.out.print(arr[i]);
        }else{
            System.out.print(arr[i] + ",");
        }

    }
    System.out.println("}");
}

public static int maxScore(int[] arr){
    int max = arr[0];
    for(int i=1;i<arr.length;i++){
        if(max<arr[i]){
            max = arr[i];
        }
    }
    return max;
}
public static int minScore(int[] arr){
    int min = arr[0];
    for(int i=1;i<arr.length;i++){
        if(min>arr[i]){
            min = arr[i];
        }
    }
    return min;
}

public static int sum(int[] arr){
    int sum = 0;
    for(int i=0;i<arr.length;i++){
        sum += arr[i];
    }
    return sum;
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值