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...

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.

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??)}

Yes (etc)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.