0

Write a program to convert the month and days into number of the days for year 2010.
Example: Input Month and days: May 16

import java.util.Scanner;
    public class A129323{
        public static void main(String [] args){

            int i = 0, numberOfDays = 0, sum = 0, previousMonth = 0, count = 0;
            Scanner input = new Scanner(System.in);
            System.out.println("Input Month and days: ");
            int month = input.nextInt();
            int days = input.nextInt();

            while(i<=month)
            {

            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
            {
                numberOfDays = 31;

            }

           if (month == 4 || month == 6 || month == 9 || month == 11)
            {
                numberOfDays = 30;

            }

            if (month == 2)
            {
                numberOfDays = 28;

            }
            i++;


        }
            sum = numberOfDays + (days - 1);
            System.out.println("Output: " + sum );
}}

this is what i had been type...
when i compile my answer can't count the previous months day...

Edited by Reverend Jim: Fixed formatting

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

In your loop you set numberOfDays to the number of days in each month, so each month you overwite the previous values. You should add each month's number of days to the previous value.

0

if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
numberOfDays = 31; (that means i need to add at here??)}

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.