Thursday, October 12, 2017

CBSE Class 12/ 11 - Informatics Practices - Java Practical Snippet-1 - Leap Year Testing (#cbseNotes)

Java Practical Snippet-1
Leap Year Testing  

CBSE Class 12/ 11 - Informatics Practices - Java Practical Snippet-1 - Leap Year Testing (#cbseNotes)


QuestionInput a year and check if the year is leap year or not.


Answer:






 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        long i = Long.parseLong(jTextField1.getText());
        String str = "";
        if (i%100 ==0) {
            if (i%400 ==0)
                str = i + " is a Leap Year";
            else
                str = i + " is a Normal Century Year";
        } else if (i%4==0)
                str = i + " is a Leap Year";
        else
                str = i + " is not a Leap Year"; 
        jLabel2.setText(str);
    }   


Screen Output:

CBSE Class 12/ 11 - Informatics Practices - Java Practical Snippet-1 - Leap Year Testing (#cbseNotes)

No comments:

Post a Comment