Leap Year detection issues

Source: Internet
Author: User

Questions about the leap year test:

Condition: 1. 4 Years a leap, 100 years do not leap, 400 years and leap.

2. Enter the year greater than 0.

3. Enter the number only.

Source:

public class Leapyear extends application {

public static void Main (string[] args) {
Leapyear.launch (args);
}

Private TextField TextField = new TextField ();

@Override
public void Start (Stage arg0) throws Exception {
Arg0.settitle ("Leapyear");

HBox HBox = new HBox (8);
Textfield.setprefcolumncount (25);
Hbox.setalignment (Pos.center_left);
Button btn = New button ();
Btn.settext ("OK");
Btn.setonaction (New Listener ());
Hbox.getchildren (). AddAll (New Label ("Please enter Year:"), TextField, BTN);

Arg0.setscene (New Scene (Hbox, 450, 80));
Arg0.show ();
}

public class Listener implements eventhandler<actionevent> {

@Override
public void handle (ActionEvent arg0) {
String str = Textfield.gettext ();
String inf = "";
if (isleapyear (Integer.parseint (str))) {
inf = "Leap year";
}
Else {
inf = "Non-leap Year";
}
Joptionpane.showmessagedialog (NULL, INF, "Information",
Joptionpane.information_message);
}
}

Private boolean isleapyear (int year) {
if (year% 4! = 0) {
return false;
}
Else if (year%!! = 0) {
return true;
}
Else if (year%!! = 0) {
return false;
}
Else {
return true;
}
}
}

Number Test Cases Results
1 1995 Non-leap year
2 2000 Leap
3 2012 Leap
4 0000 Leap
5 1900 Non-leap year

Test results:

1.

2.

3.

4.

5.

But there is a problem with the error when the input is empty. There are also errors when you enter a flight number.

Leap Year detection issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.