Question

in java Write a program that displays all the leap years, eight per line, from 101...

in java

Write a program that displays all the leap years, eight per line, from 101 to 2500, separated by one space. Meanwhile display the number of leap years in this period of year.

Homework Answers

Answer #1
public class PrintLeaps {

    public static void main(String[] args) {
        int count = 0;
        for (int year = 101; year <= 2500; year++) {
            if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {
                System.out.print(year + " ");
                ++count;
                if (count % 8 == 0)
                    System.out.println();
            }
        }
        System.out.println("\nThere were " + count + " leap years from 101 to 2500");
    }
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Java program that reads words from a text file and displays all the words...
Write a Java program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. 1. You must use one of following Concrete class to store data from the input.txt file. Vector, Stack, ArrayList, LinkedList 2. To sort those words, you should use one of existing interface methods available in Collection or List class.
given an integer, write a program that displays the number as follows first line         all digits...
given an integer, write a program that displays the number as follows first line         all digits second line   all except first digit third line        all except first two digits ..... last line          the last digit ex) 5 6 7 8 6 7 8 7 8 8
Need this program in Java Develop (using C++ or Java language) the software application described below....
Need this program in Java Develop (using C++ or Java language) the software application described below. Write a program that prints the day number of the year, given the date is in the form month-day-year. For example, if the input is 1-1-09, the day number is 1; if the input is 12-25-09, the day number is 359. The program should check for a leap year. A year is a leap year if it is divisible by 4 but not divisible...
using python Write a program that displays all of states in the U.S. and display each...
using python Write a program that displays all of states in the U.S. and display each state that begins with the letter A.
Design a program in Java that displays all of the prime numbers from 1 through 100....
Design a program in Java that displays all of the prime numbers from 1 through 100. The program should have a loop that calls the isPrime() function. 11 Prime Numbers List (15 points) Use CONSTANTS to set the maximum number in the table to 100 and the number of entries per row to 5.   Table of prime numbers from 1 to 100 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59...
given an integer, write a program in C++ that displays the number as follows first line        ...
given an integer, write a program in C++ that displays the number as follows first line         all digits second line   all except first digit ... last line          last digit ex) 5 6 7 8 6 7 8 7 8 8
Write a java program that repeatedly prompts the user to input a string starting with letters...
Write a java program that repeatedly prompts the user to input a string starting with letters from the English alphabet. The program must stop getting input when the user inputs the string “STOOOOP”. Then the program must display the words starting with each letter from the alphabet in a separate line (e.g. you need to make a new line after all words starting with a specific letter are finished.
Write a Java program that reads employee information from the file “employee.txt” then the program will...
Write a Java program that reads employee information from the file “employee.txt” then the program will display his/her information on the screen. The file contains the Employee’s Name, age,join date, quit date, and salary. • For each year the employee is in the company,10 days of sick leave are allowed. So, if an employee is in the company for two years, 20 days of sick leave are allowed. • For each year the employee is in the company, one-month salary...
Write code in JAVA Write a program that will output a right triangle based on user...
Write code in JAVA Write a program that will output a right triangle based on user specified input height (int) and specified input symbol (char).The first line will have one user-specified character, such as % or *. Each subsequent line will have one additional user-specified character until the number in the triangle's base reaches specified input height. Output a space after each user-specified character, including after the line's last user-specified character. Hint: Use a nested for loop. Ex:If the input...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...