?
Solved

Writing a program using the IF statement

Posted on 2004-10-26
3
Medium Priority
?
218 Views
Last Modified: 2010-04-01
I have to write a question usinf the IF statement.  I have to write a program to check whether or not a year inputted is or was a leap year.  A year is a leap year if it is evenly divisible by 4, except that any year divisible by 100 is a leap year only if is divisble by 400?
0
Comment
Question by:sniper4897
  • 2
3 Comments
 

Author Comment

by:sniper4897
ID: 12418299
//Steven Zecca
package proj2stz;
import javax.swing.*;
public class LeapYear
{
  public static void main(String[] args)
  {
  String s1,s2,s3;
  int x,y;
  s1=JOptionPane.showInputDialog("Enter a year, please?");
  y=Integer.parseInt(s1);
  x=Integer.parseInt(s1);
  if(y/4=x)
  {
    System.out.println("x is a leap year");
  }
  else
  {
      System.out.println("x is not a leap year");
 
  }
  }
}
0
 

Author Comment

by:sniper4897
ID: 12418304
package proj2stz;
import javax.swing.*;
public class LeapYear
{
  public static void main(String[] args)
  {
  String s1,s2,s3;
  int x,y;
  s1=JOptionPane.showInputDialog("Enter a year, please?");
  y=Integer.parseInt(s1);
  x=Integer.parseInt(s1);
  if(y/4=x)
  {
    System.out.println("x is a leap year");
  }
  else
  {
      System.out.println("x is not a leap year");
 
  }
  }
}
this is what i have..but it doesn't work
0
 

Accepted Solution

by:
msasikala earned 400 total points
ID: 12418741
if( (y%100==0 && y%400==0) ||(y%100!=0 && y%4==0))
{
     System.out.println("y is a leap year");
}
else{
      System.out.println(" y is not a leap year");
}
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The PowerShell Core 6.0 of .NET release is just the beginning. The upcoming PowerShell Core 6.1 would have artificial intelligence and internet of things capabilities. So many things to look forward to in the upcoming release.
A discussion about four distinct advantages of using a Custom Software Development solution.
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Suggested Courses

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question