Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Using Java program determines whether it is a leap year     - PCM audio under Linux (Linux)

- Four levels to deal with Linux server attacks (Linux)

- Spark parquet merge metadata problem (Server)

- Manually generate AWR reports (Database)

- Server Security Analysis attack on Linux (Linux)

- Lua4.0 interpreter documents (Programming)

- CentOS installation pycurl (Linux)

- VMware virtual machine operating system log Error in the RPC receive loop resolve (Linux)

- GAMIT10.5 under CentOS installation (Linux)

- The Java way to stop a thread of execution (Programming)

- Redis is installed in Ubuntu 14.04 (Database)

- Using Python to find a particular file extension directory (Programming)

- Based Docker build stand-alone high-availability cluster Hadoop2.7.1 Spark1.7 (Server)

- Oracle archive log size than the size of the online journal of the much smaller (Database)

- Use nice, cpulimit and cgroups limit cpu usage (Linux)

- CentOS environment prepared crontab scheduled tasks (Linux)

- Compare Dalvik virtual machine and the JVM (Linux)

- Ubuntu Linux use ufw or iptables firewall configuration (Linux)

- Ant command-line compiler Android project (Programming)

- Java8 Lambda expressions and flow operations (Programming)

 
         
  Using Java program determines whether it is a leap year
     
  Add Date : 2018-11-21      
         
         
         
  We know that (1) if the whole hundred years, can be divisible by 400 is a leap year; (2) if not the whole hundred year divisible by 4 is a leap year. Every 400 years, there are 97 leap years. In view of this, Java programs can make the following design:

The first step, it is determined whether the year is divisible by 400, it can then, is a leap year. Such as 1600, 2000, 2400 is a leap year.

The second step, the first step is not established on the basis of the judgment whether the year is divisible by 100, if it is, it is not a leap year. Such as 1900, 2100, 2200 is not a leap year.

The third step, the second step is not established on the basis of the judgment whether the year is divisible by 4, if it is, it is a leap year. Such as 1996, 2004, 2008 is a leap year.

The fourth step is not established on the basis of the third step, it is not a leap year. Such as 1997, 2001 and 2002 is not a leap year.

  
import java.util.Scanner; // into the scanner

public class runnian

{

    public static void main (String [] args) // Sting [] args do not forget to write came

    {

    Scanner s = new Scanner (System.in); // declare variables scanner

    System.out.println ( "Please enter the year"); // prompted Year

    int nianfen = s.nextInt (); // get the year value of the next line of input

    if (nianfen% 400 == 0) {System.out.println (nianfen + "is a leap year");} // determines whether or not divisible by 400

    else if (nianfen% 100 == 0) {System.out.println (nianfen + "not a leap year");} // determines whether or not divisible by 100

        else if (nianfen% 4 == 0) {System.out.println (nianfen + "is a leap year");} // determines whether or not divisible by four

          else {System.out.println (nianfen + "not a leap year");}

    }

}

After preliminary testing, this program can correctly determine whether it is a leap year. This procedure If errors and omissions, please treatise. We must realize there are other methods, please reply provided.

=======================

After studying the video in teaching others, wrote the first two kinds of methods to achieve, you can use only one if-else statements. Code is as follows:


import java.util.Scanner;

public class runnian

{

    public static void main (String [] args)

    {

    Scanner s = new Scanner (System.in);

    System.out.println ( "Please enter the year");

    int nianfen = s.nextInt ();

    if (! nianfen% 4 == 0 && nianfen% 100 = 0 || nianfen% 400 == 0) {System.out.println (nianfen + "is a leap year");}

    // Year divisible by 4 but not divisible by 100, or can be divisible by 400 years

        else {System.out.println (nianfen + "not a leap year");}

    }

}
     
         
         
         
  More:      
 
- System Safety: Windows and Linux platforms (Linux)
- The specified user to execute commands under Linux (Linux)
- To execute the cp command prompt type skip folder under CentOS (Linux)
- Java memory area (Programming)
- MNIST presentation and database conversion (Database)
- Java reflection technology explain (Programming)
- CentOS 7 virt-manager can not connect a local hypervisor (Linux)
- Build a Linux development environment under STC89C52RC (Linux)
- Use calcurse schedule appointments and to-do in the Linux terminal (Linux)
- Shell Common Command Summary (Programming)
- Unetbootin make use U disk loading Linux system (Linux)
- Android Qemu GPS module (Programming)
- Generated characters using Java Videos (Programming)
- Linux process stack and process function stack frame (Linux)
- Ubuntu Apache2 setting, problem solving css, pictures, etc. can not be displayed (Server)
- Linux character device - a simple character device model (Linux)
- CentOS iptables firewall enabled (Linux)
- Automated Password Generator: Linux under a special password generator (Linux)
- Gentoo: !!! existing preserved libs problem (Linux)
- The next key to install Linux bash script PowerShell (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.