Days of each month

Hey I need help with the loops, im kind of new with this and im trying

Page 1 of 1

3 Replies - 3925 Views - Last Post: 12 November 2009 - 10:18 PM Rate Topic: -----

#1 jrob91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-November 09

Days of each month

Posted 12 November 2009 - 02:44 PM

public class calendar{
	public static void main(String[] args){
	
	String months[]={"January","February","March","April","May",
							"June","July","August","September","October",
							"November","December"};
							
	int DaysinMonth[]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	}
		for(int i=0;i< months.length;i++){
			System.out.println(months[i]);
		for(int i=0;i< DaysinMonth.length;i++){
			System.out.print(DaysinMonth[i]);
		}
		}
	}



Hey I need help with the loops, im kind of new with this and im trying to figure how to do this. Can anyone help, I know since im making arrays that I need to have for loops but i dont know how to do it. Here are the directions.


Design a program that displays the number of days in each month. The program’s output should be similar to this:

January has 31 days.
February has 28 days.
March has 31 days.
April has 30 days.
May has 31 days.
June has 30 days.
July has 31 days.
August has 31 days.
September has 30 days.
October has 31 days.
November has 31 days.
December has 31 days.

The program should have two parallel arrays: a 12-element String array that is initialized with the names of the month, and a 12-element Integer array that is initialized with the number of days in each month. To produce the output specified, use a loop to step through the arrays getting the name of a month and the number of days in that month.

Is This A Good Question/Topic? 0
  • +

Replies To: Days of each month

#2 WaHooCrazy7  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 19
  • Joined: 09-November 09

Re: Days of each month

Posted 12 November 2009 - 02:54 PM

Since the arrays are of the same size, you can make a for loop to step through them and use the same index to get the data from both arrays and print it out.

e.g.
for(int i = 0; i < 12; i++){
   system.out.println arrayOne[i] + " has: " + arrayTwo[i] + " days.";
}


This post has been edited by WaHooCrazy7: 12 November 2009 - 02:54 PM

Was This Post Helpful? 0
  • +
  • -

#3 jrob91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-November 09

Re: Days of each month

Posted 12 November 2009 - 10:05 PM

View PostWaHooCrazy7, on 12 Nov, 2009 - 01:54 PM, said:

Since the arrays are of the same size, you can make a for loop to step through them and use the same index to get the data from both arrays and print it out.

e.g.
for(int i = 0; i < 12; i++){
   system.out.println arrayOne[i] + " has: " + arrayTwo[i] + " days.";
}




Thanks man, it works, I appreciate it
Was This Post Helpful? 0
  • +
  • -

#4 WaHooCrazy7  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 19
  • Joined: 09-November 09

Re: Days of each month

Posted 12 November 2009 - 10:18 PM

no problem, glad i could be of assistance :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1