java输出结果中12哥数,需要5列一行显示,但是最后一列不满5列,需要用“-”补充满,请问需要怎么写?
int[] a= {2,32,234,123,45,231,68,45,898,342,64,213};
Random random = new Random() ;
for(int i=0;i<a.length;i++)
{
if((i+1)%5==0&&i!=0)
{
System.out.print("a["+i+"]="+a[i]+"\n");
}else{
System.out.print("a["+i+"]="+a[i]+" ");
}
}
这个是我写的,但是我不知道该怎么判断加“-”,
别人告诉我这样写,但是没成功啊
int[] a1= {2,32,234,123,45,231,68,45,898,342,64,213};
Random randoma = new Random() ;
for(int i=0;i<a1.length;i++)
{
if((i+1)%5==0&&i!=0)
{
System.out.print("a1["+i+"]="+a1[i]+"\n");
}else if((i+1)%5!=0){
System.out.print("a1["+i+"]="+a1[i]+" ");
int index = ((((i+1)/5)+1)*5);
for(int m = i+1;m < index;m++){
System.out.print("-"+"\t");
}
}
}
int[] a= {2,32,234,123,45,231,68,45,898,342,64,213};
Random random = new Random() ;
for(int i=0;i<a.length;i++)
{
if((i+1)%5==0&&i!=0)
{
System.out.print("a["+i+"]="+a[i]+"\n");
}else{
System.out.print("a["+i+"]="+a[i]+" ");
}
}
这个是我写的,但是我不知道该怎么判断加“-”,
别人告诉我这样写,但是没成功啊
int[] a1= {2,32,234,123,45,231,68,45,898,342,64,213};
Random randoma = new Random() ;
for(int i=0;i<a1.length;i++)
{
if((i+1)%5==0&&i!=0)
{
System.out.print("a1["+i+"]="+a1[i]+"\n");
}else if((i+1)%5!=0){
System.out.print("a1["+i+"]="+a1[i]+" ");
int index = ((((i+1)/5)+1)*5);
for(int m = i+1;m < index;m++){
System.out.print("-"+"\t");
}
}
}