【发布时间】:2015-05-13 02:19:00
【问题描述】:
我正在处理一项需要更改 Country 类的 Java 任务,以便它打印国家数据库表中的每个国家,而不仅仅是一个国家。我尝试了各种实例,但无法让它显示所有实例。我对 Java 很陌生,所以我知道我以某种方式弄乱了语法,或者它公然在我面前,我已经研究这个太久了,需要另一双眼睛。到目前为止,这是我从国家表中显示一个国家的内容。
public class CountryMain {
public static void main(String[] args) {
ReadCountryDB rcdb = new ReadCountryDB();
List<Country> countries = rcdb.getCountries();
Country firstCountry = countries.get(0);
System.out.println("First country:");
System.out.println("Name: " + firstCountry.getName()
+ " Population: " + firstCountry.getPopulation()
+ " Median Age: " + firstCountry.getMedianAge());
}
}
我知道我需要更改的“Country firstCountry = countries.get(0)”方法部分,我尝试过未定义的 getAll,但我对需要定义的内容感到困惑,所以它拉国家数据库中的所有内容。
非常感谢您对此的任何帮助。
【问题讨论】:
-
使用
for loop?
标签: java arrays class sorting methods