gpt4 book ai didi

java - 在java中并排显示并行数组

转载 作者:行者123 更新时间:2023-11-29 07:58:27 24 4
gpt4 key购买 nike

我是 java 的新手,我已经编写了代码来显示以下并行数组的值:

short[] Years = {1995, 1997, 1998,1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012};

String[] Months = {"January", "February", "June", "January", "March", "June", "July", "August", "September", "March", "May", "January", "March", "July", "November", "March", "June"};

目前,当我运行它时,它们显示在彼此之上。我试图让它并排显示。我该怎么做?

这是显示它们的代码片段:

System.out.println("Years");
for(short temp: years)
{
System.out.println(temp);
}
System.out.println("Months");
for(String temp: months)
{
System.out.println(temp);
}

最佳答案

如果它们的长度相等:

for (int i = 0; i < Years.length; i++) {
System.out.println(Years[i] + '\t' + Months[i]);
}

关于java - 在java中并排显示并行数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16098781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com