mercredi 21 septembre 2016

If statement and resolving a boolean as a variable

I'm trying to write a simple program that determines whether or not a certain year (Inputted in the Input Dialog, an int named 'nmbr') In the second if-statement, after determining whether or not nmbr is a multiple of 4 (A new Year) I want to print out "(nmbr) is/is not a New Year" - but the two printlns' both come out with a "lP cannot be resolved to a variable" error. What is wrong with the variable, and how can i fix the problem?

import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.JLabel;
    import javax.swing.JButton; 
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    public class LeapYear {

        public static void main(String[] args) {
            int nmbr;
            nmbr = Integer.valueOf(JOptionPane.showInputDialog("enter any year"));
            JPanel planel = new JPanel();

            if (nmbr>0 && 4%nmbr==0) {
                boolean lY = true;
            }

            else {
                boolean lY = false;

            }
                if(lY = true) {
                    System.out.println(nmbr + " is a new year");
                }
                if(lY = false) {
                    System.out.println(nmbr + " is not a new year");
                }

        }
    }

Aucun commentaire:

Enregistrer un commentaire