Monday, August 12, 2019

BlueJ Program on Counting Numbers of Days



Program on counting number days from the start of the year




Our next program on array is an interesting one. The user will enter the month number (1 to 12), date and year. Our program will display the total number days from the start of the year.

import java.io.*;
class MyDay
{
int month,day,tday,year,i,lip=0;
boolean a=true,b=true;
int dpm[12]={31,28,31,30,31,30,31,31,30,31,30,31};
void take() throws IOException
{

while(a)
{
System.out.println ("enter the month(1to12):-");
month=Integer.parseInt(br.readLine());
if(month>12)
{
System.out.println ("Enter the proper month:-");
continue;
}
a=false;
}
while(b)

{
System.out.println ("Enter the day(1to31):-\n");
day=Integer.parseInt(br.readLine());
if(day>31)
{
System.out.println ("enter the proper day:-\n");
continue;
}
b=false;
}
tday=day;
System.out.println ("Enter the year:-");
year=Integer.parseInt(br.readLine());
for(i=0;i < month-1;i++)
{
tday=tday+dpm[i];
}
for(i=0;i< 2;i++)
{
if(year%10!=0)
break;
year=year/10;
}if(i==2)
{
if(year%400==0)
lip=1;
}
else if(year%4==0)lip=1;if((lip==1)&&(month>2))
tday=tday+1;
System.out.println("total days from start of the year is:”+tday);
}
}

If you have any doubt in any program, pl. feel free to put your comments. I am here to clear your doubts.

Related Post: BlueJ Programs on Numeric Array

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner