自动填充随机数,新手路过。。。多多指教,感觉我的思路更清晰点
public class 数组合并1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int [] a = new int [8];
int [] b = new int [7];
for(int i = 0; i < a.length; i++)
{
a[i] = (int)(Math.random()*100);
}
for(int i = 0; i < b.length; i++)
{
b[i] = (int)(Math.random()*100);
}
System.out.print("数组a为");
for (int each : a)
{
System.out.print(each+" ");
}
System.out.println("\n");
System.out.print("数组b为");
for (int each : b)
{
System.out.print(each+" ");
}
System.out.println("\n");
int [] c = new int [a.length+b.length];
for(int i = 0; i < a.length; i++)
{
c[i] = a[i];
}
for(int i = 0; i < b.length; i++)
{
c[i+(a.length)] = b[i];
}
System.out.print("数组c为");
for(int each : c)
{
System.out.print(each+" ");
}
}
}
|