Daniel Ray
Posts: 53
Nickname: budoray
Registered: Oct, 2002
|
|
Re: Hel...help...help...
|
Posted: Jun 14, 2004 10:23 AM
|
|
Not sure if this is what you wanted, but it will show you how to iterate through an array and print the data on separate lines. Post your desired output if I read your post incorrectly.
public class RainFall { public double[] rainFor12Months = { 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.1, 2.2, 2.3 }; public String[] postalCodes = { "32210", "32211", "32212" }; public String[] years = { "1971", "1972", "1973" }; public RainFall(){ } private void printRainFallForYear(String postalCode, String year){ int length = rainFor12Months.length; for(int i=0; i<length; i++){ System.out.println(rainFor12Months + "\t\t" + postalCode + "\t\t" + year); } System.out.println(); } public void printRainFallForAllYears(){ int length = years.length; for(int i=0; i<length; i++){ System.out.println("Rainfall PostalCode Year"); printRainFallForYear(postalCodes, years); } } public static void main(String[] args) { new RainFall().printRainFallForAllYears(); }
}
|
|