Solved

Writing a program using the IF statement

Posted on 2004-10-26
210 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
Question by:sniper4897
    3 Comments
     

    Author Comment

    by:sniper4897
    //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
    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:
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    Converting a Hibernate Query to use parameters 5 101
    xjc and jaxb 2 83
    trouble with PDF encryption using itext-1.3.1 17 66
    java operators 3 54
    When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
    Are you using email marketing software? If not, you're missing out on effortless marketing and the reaching of desired conversion rates through email marketing software.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    933 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now