that is expected output is

sun   mon   tue  wed  thu  fri  sat
                       1    2    3
4      5     6    7     8   9    10
....
...
...
29  30  31

my code:

static void print_31days(int a[][]){
	
	int i=1;
	while(i<=31)
 {
		int some=0;//some is the startdate of the month of the 
		while( some<5){
			some++;
			System.out.print("---"+"\t");
		}
		
		for(int k=0;k<5&&i<=31;k++){//k is the number of weeks
			
		for(int j =1;j%8!=0&&i<=31;j++){//j is the number of days
			
			a[k][j]=i;
			i++;
			//System.out.println("\t"+"\t");
			
			
			
				if(j==3){
				System.out.println("");
			}
			System.out.print(a[k][j]);
			System.out.print("\t");
			
		}
		System.out.println("");
		}
	}
}

output wat i got is this

enter month
jan\
enter the number of the month
1
month is jan\
number of month is 1

sun	mon	tue	wed	thur	fri	sat	
================================================================================================
sat 	sun 	mon 	tue 	wed 	thu 	fri 	
---	---	---	---	---	1	2	
3	4	5	6	7	
8	9	
10	11	12	13	14	
15	16	
17	18	19	20	21	
22	23	
24	25	26	27	28	
29	30	
31

Edited 5 Years Ago by masijade: added code tags

try k less than 7...it most likely won't work perfectly, but it will give you a hint. tell us what does your int[][] a parameter to the method hold. it's dimensions. besides, you could reach the effect with a one-dimensional array as well...

for(int j =1;j%8!=0 ...
why not just
for(int j =1;j<8 ...

if(j==3){System.out.println("");}
looks very wrong, and is why you are getting extra line breaks. Remove it and the formatting is OK apart from the very first line. I suspect the mystery thing you are doing with "some" at the start is to do with getting the first line offset right, so you probably need to use this to get the first line printed OK

well, remove lines 22 to 24 first. you do not need that if just yet. then see what .you get, perhaps that will direct you.

and why don't use java.util.Calendar or Date (and only hard code Month + Year for expected and correct output)

no i wanted to implement on my own ,was stuck in the middle so thought of getting help from techies.
thanks guys i got it.

This question has already been answered. Start a new discussion instead.