Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

New to Java, need to create Leap Year Program

843785Sep 25 2008 — edited Sep 25 2008
Hello, Im new to Java, so expect the worst programming ever, hahaha. Im trying to create a program that calculates if the year entered is a leap year, also I need it to reloop and ask to enter another year, or enter a specific number to exit, I know it probably has something to do with sentinel values. Here is my lame source code, please excuse its sloppyness. It compiles right, except I get its not a leap year everytime, for any year, haha, something is probably wrong with the year%100 !=0, hahaha.
import javax.swing.*;

// This program takes a year given and tells you if it is a leap year


public class Hw2
{
    public static void main( String[] arg )
    {
	
	double year;
	
        year = Integer.parseInt( JOptionPane.showInputDialog("Please enter the year: \n" + " or -99  to Quit" ) );

	if(( year % 4 == 0) && (year % 400 == 0) && (year % 100 != 0 ))
		JOptionPane.showMessageDialog( null, year + " is a leap year" );
			else
				JOptionPane.showMessageDialog( null, year + " is not a leap year" );	
	
	System.exit( 0 );
        
    }
    
    
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 23 2008
Added on Sep 25 2008
6 comments
501 views