Question

In: Computer Science

CS 206 Visual Programming, Netbeans Problem: Write a Java program that displays all the leap years,...

CS 206 Visual Programming, Netbeans

Problem: Write a Java program that displays all the leap years, 10 per line, from 1001 to 2100, separated by exactly one space. Also display the total number of leap years in this period. Hints: you need to use a loop ( for-loop is more suitable)

Solutions

Expert Solution

//TestCode.java
public class TestCode {
    public static boolean isLeapYear(int userYear){
        if(userYear % 4 == 0 && userYear % 100 != 0){
            return true;
        }
        else if(userYear % 400 == 0){
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        int k = 1;
        for(int i = 1001;i<=2100;i++){
            if(k%10==0){
                System.out.println();
                k = 1;
            }
            if(isLeapYear(i)){
                System.out.print(i+" ");
                k++;
            }
        }
    }
}


Related Solutions

CS 206 Visual Programming, Netbeans Understand and modify the attached GCDMethod.java so it can find the...
CS 206 Visual Programming, Netbeans Understand and modify the attached GCDMethod.java so it can find the greatest common divisor of three numbers input by the user.  Hints: modify the gcd() method by adding the third parameter. import java.util.Scanner; public class GCDMethod { /** Main method */ public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in); // Prompt the user to enter two integers System.out.print("Enter first integer: "); int n1 = input.nextInt(); System.out.print("Enter second integer: ");...
Java Programming Write a program that displays the following pattern *                         *       &nbsp
Java Programming Write a program that displays the following pattern *                         *          *          * *          *          *          *          *          *          *          *          *          *          *          *             *          *          *          *          *                         *          *          *                                     * Printing Pattern A * ** *** **** ***** ****** ******* Printing Pattern B ******* ****** ***** **** *** ** * Printing Pattern C * ** *** **** ***** ****** *******
java programming question: "Write a program that displays a page on a topic of interest to...
java programming question: "Write a program that displays a page on a topic of interest to you (e.g., a sport, a city). Include at least one image and one shape (which can be text). " I wanted to do a soccer page but I don't know how to put pictures from the internet on Java. As for my object, I wanted to make a soccer ball. My professor has been really confusing in explaining graphics so any help is appreciated!
Problem 4 • Use Java Collections to write a small program using NetBeans to do the...
Problem 4 • Use Java Collections to write a small program using NetBeans to do the following: 1. Create a queue object of Integer items, myQueue. 2. Create a stack object of Integer items, myStack. 3. Enqueue the integers 10, 20. 30, .., 100 into myQueue, in that order. 4. Push the integers 10, 20, 30, ..., 100 into myStack, in that order. 5. Display the message: "Here are the elements of myQueue:". 6. Remove and display the front element...
Java Write a program that displays all the numbers from 100 to 200 that are divisible...
Java Write a program that displays all the numbers from 100 to 200 that are divisible by 5 or 6, but not both Make sure all instructions and outputs for the user are explicit
Write a Java program that reads a name and displays on the screen.
Write a Java program that reads a name and displays on the screen.
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
Write a Java program that reads words from a text file and displays all the non-duplicate...
Write a Java program that reads words from a text file and displays all the non-duplicate words in ascending order. The text file is passed as a command-line argument. Command line argument: test2001.txt Correct output: Words in ascending order... 1mango Salami apple banana boat zebra
Write a program in assembly language that outputs the leap years between a beginning and an...
Write a program in assembly language that outputs the leap years between a beginning and an ending year. 1. Initialize $a0 and $a1 with the beginning and ending years. 2. Print out the leap years between 1970 and 2030. OUTPUT: From 1970 to 2030: 1972 … 2028
Hello this is an intro to CS course. The question is: Using Java, write a program...
Hello this is an intro to CS course. The question is: Using Java, write a program that asks the user to enter three numbers. Then passes these numbers to the following methods and prints out the numbers returned by these methods. largest() – returns the largest of the three numbers smallest() – returns the smallest of the three numbers median() – returns the median of the three numbers Example output is given below: Enter three numbers 10 4 16 The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT