这个没什么难度。 楼主还是多锻炼下吧。public class Test3 { public static void main(String[] args) { int[] colum=new int[5]; Scanner s=new Scanner(System.in); for(int i=0;i<5;i++){ colum[i]=s.nextInt(); } System.out.println(getMax(colum)); } public static int getMax(int[] colum){ int max=colum[0]; for(int i:colum){ if(i>max){ max=i; } } return max; } }
public class Test{ public static int getMaxValue(int[] x){ //bubble sort for(int a=1;a<x.length;a++){ for(int b=x.length-1;b>=a;b--){ if(x[b-1]<x[b]){ int temp = x[b-1] ; x[b-1] = x[b]; x[b] = temp; } } } //return max value return x[0]; }
public static void main(String[] args){ //if you wanted the array inputed by user,you can use the class of Scaner int[] test = {1,24,5,2,3}; int maxValue = getMaxValue(test); System.out.println(maxValue); } }
楼主还是多锻炼下吧。public class Test3 {
public static void main(String[] args) {
int[] colum=new int[5];
Scanner s=new Scanner(System.in);
for(int i=0;i<5;i++){
colum[i]=s.nextInt();
}
System.out.println(getMax(colum));
}
public static int getMax(int[] colum){
int max=colum[0];
for(int i:colum){
if(i>max){
max=i;
}
}
return max;
}
}
public class Test{
public static int getMaxValue(int[] x){
//bubble sort
for(int a=1;a<x.length;a++){
for(int b=x.length-1;b>=a;b--){
if(x[b-1]<x[b]){
int temp = x[b-1] ;
x[b-1] = x[b];
x[b] = temp;
}
}
}
//return max value
return x[0];
}
public static void main(String[] args){
//if you wanted the array inputed by user,you can use the class of Scaner
int[] test = {1,24,5,2,3};
int maxValue = getMaxValue(test);
System.out.println(maxValue);
}
}