第一题
package test;
import java.util.Random;
public class test3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
shuzu a=new shuzu();
a.shu();
int max=0;
for(int i=0;i<25;i++)
if(max
{
max=a.b[i];
}
System.out.println("最大值为"+max);
for(int i=0;i<25;i++)
if(max==a.b[i])
{
System.out.println("其下标为"+i);
}
}
}
class shuzu{
int b[]=new int[25];
public void shu() {
for(int i=0;i
b[i]=new Random().nextInt(100)+1;
System.out.print(b[i]+"\t");
if((i+1)%5==0) {
System.out.println();
}
}
}
}
第二题:package test;
import java.util.Arrays;
import java.util.Random;
public class test4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
shuzu1 a=new shuzu1();
a.shu();
for(int i:a.b) {
Arrays.sort(a.b);
}
System.out.println(Arrays.toString(a.b));
}
}
class shuzu1{
int b[]=new int[40];
public void shu() {
for(int i=0;i
b[i]=new Random().nextInt(100)+1;
System.out.print(b[i]+"\t");
if((i+1)%8==0) {
System.out.println();
}
}
}
}
二维数组没学过,用一维数组替代了,求指教