【发布时间】:2016-04-14 23:49:50
【问题描述】:
这是我的代码。列不会打印出来,但数字会打印出来。如何将数字对齐到不同的列中。一列元素 0-9 和其他三列数组 1-3
import java.util.Scanner;
public class IntroductiontoArrays
{
public static void main (String [] args)
{
// put your code here
final int max=10;
int[] first = new int[max];
int [] order = new int [10];
Scanner input = new Scanner(System.in);
for (int x=0; x<9; x++)
{System.out.print("Enter a two-digit number:");
first [x]=input.nextInt();
order [x]=x;
}
System.out.println("\n"+"Elements" + "\t" + "Array 1" + "\t" + "Array 2" + "\t" + "Array 3" + "\t");
int[] second = {2,4,6,8,10,12,14,16,18,20};
int[]third=new int[max];
for (int lcv=0; lcv<9; lcv++)
{
int a=(int)(Math.random()*10);
third[lcv]=a;}
for (int lcv=0; lcv<=9; lcv++)
{ System.out.print(lcv + "\t" + first[lcv] + "\t" + second[lcv]+ "\t"+ third[lcv]);}
}
}
【问题讨论】: