Java Practical Snippet-1
Leap Year Testing
Question: Input a year and check if the year is leap year or not.
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:
No comments:
Post a Comment
We love to hear your thoughts about this post!
Note: only a member of this blog may post a comment.