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 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
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.
I am trying to write code for a program in Visual Studo using Visual Basic programming...
I am trying to write code for a program in Visual Studo using Visual Basic programming language that computes the factorial of an entered number by using a For Loop. My problem is that it keeps re-setting the variable for Factorial. Below is my code if anyone can help. I want it to multiply the given number by that number - 1, then continuing to do so until it hits zero without multiplying by zero. Private Sub BtnCalculate_Click(sender As Object,...
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
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text label and a button.When the program begins, the label displays a 0. Then each time the button is clicked, the number increases its value by 1; that is each time the user clicks the button the label displays 1,2,3,4............and so on.
in java Write a Java Program that displays a menu with five different options: 1. Lab...
in java Write a Java Program that displays a menu with five different options: 1. Lab Test Average Calculator 2. Dice Roll 3. Circle Area Calculator 4. Compute Distance 5. Quit The program will display a menu with each of the options above, and then ask the user to enter their choice. There is also a fifth option to quit, in which case, the program will simply display a goodbye message. Based on the user’s choice, one of the options...
Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents....
Write a JAVA program that displays a table of the Celsius temperatures and their Fahrenheit equivalents.  The formula for converting a temperature from Celsius to Fahrenheit is F = 9/ 5 C + 32 where F → Fahrenheit temperature C → Celsius temperature.  Allow the user to enter the range of temperatures in Celsius to be converted into Fahrenheit.  Your program must use a loop to display the values of the temperature conversions (see sample output). Sample...
in java Write a program that reads in ten numbers and displays the number of distinct...
in java Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct numbers. Here is the sample run of the program: Enter...
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester. The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT