Java简单程序编写,超级感谢啊(返回数组元素中的最大值的下标)
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/10/05 00:36:33
Java简单程序编写,超级感谢啊(返回数组元素中的最大值的下标)
public static int max(Comparable table[])
//返回数组元素中的最大值的下标
(注意:参数是Comparable table[])
我写的是有警告的,
public static int max(Comparable table[])
//返回数组元素中的最大值的下标
(注意:参数是Comparable table[])
我写的是有警告的,
public static int max(Comparable[] table) {
if(table.length==0){
return -1;
}else{
int temp = 0;
Comparable c = table[0];
for(int i=1;i0){
temp = i;
}
}
return temp;
}
}
测试结果:
最大下标:4
再问: 你的也有N个警告,晕啊,难道大家写的都这样吗,如果这么简单我需要问吗
再答: 我晕啊,警告的原因是因为没有指定Comparable的类型啊,这个并不影响程序运行啊!如果你指定为Integer的话,你就这么写: public static int max(Comparable[] table) { if(table.length==0){ return -1; }else{ int temp = 0; for(int i=1;i0){ temp = i; } } return temp; } }===================================================================== 这样的话,就没有警告了啊!不过这个方法就只能比较Integer类了!如果楼主想比较其它类,那就把Integer改掉就行了,哎,警告是小事情,楼主平常心,平常心!
if(table.length==0){
return -1;
}else{
int temp = 0;
Comparable c = table[0];
for(int i=1;i0){
temp = i;
}
}
return temp;
}
}
测试结果:
最大下标:4
再问: 你的也有N个警告,晕啊,难道大家写的都这样吗,如果这么简单我需要问吗
再答: 我晕啊,警告的原因是因为没有指定Comparable的类型啊,这个并不影响程序运行啊!如果你指定为Integer的话,你就这么写: public static int max(Comparable[] table) { if(table.length==0){ return -1; }else{ int temp = 0; for(int i=1;i0){ temp = i; } } return temp; } }===================================================================== 这样的话,就没有警告了啊!不过这个方法就只能比较Integer类了!如果楼主想比较其它类,那就把Integer改掉就行了,哎,警告是小事情,楼主平常心,平常心!
Java简单程序编写,超级感谢啊(返回数组元素中的最大值的下标)
java返回矩阵元素的最大值 急
输入4×4的数组,编写程序实现:(1)求出对角线上各元素的和; (2)求出对角线上行、列下标均为偶数的
一个有10个元素的数组(17,86,67,83,65,49,26,92,38,42),编写程序找出其中最大数和气下标,
用JAVA 编写程序,从键盘读入10个整数存入数组,输出最大值,最小值及它们所在数组中的位置
定义一个长度为20的整型数组,并初始示数组中的所有元素,每行5个元素,并求最大值及其下标,最小值及其下标,平均值
用VB编写一个程序,计算出给定的10*10矩阵(存放在二维数组A中)每行元素的最大值和每列元素的最小值
编写一个函数,其功能是求给定数组中的最小值与最大值的元素
假定某一个数组有10个元素(下标值从1开始),各元素的值是在1到100之内的整数,通过随机函数产生.现要求编写程序,对这
假定某一个数组有10个元素(下标值从1开始),各元素的值是在1到100之内的整数,通过随机函数产生.现在要求编写程序,对
程序定义了 4× 4 的二维数组,请编写程序,给二维数组赋值,并使数组下半三角元素中的值乘以n .
【c语言】编写程序,求数组a中前n个元素的最大值max、最小值min及平均值avg.