Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: how to make an if say that it doesnt equal

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Angry how to make an if say that it doesnt equal

    i am having problem with this. i have google and search but i cant seem to figure it out

     
    /**
    The date June 10, 1960, is special because when we write it in the
    following format, the month times the day equals the year: 6/ 10/ 60
    Write a program that asks the user to enter a month ( in numeric
    form), a day, and a two-digit year. The program should then determine
    whether the month times the day is equal to the year. If so, it should
    display a message saying the date is magic. Otherwise, it should
    display a message saying the date is not magic.
    */
    import javax.swing.JOptionPane;
     
    public class Year
    {
    	public static void main(String[] args)
    	{
     
    	int month;
     
    	int day;
     
    	int year;
     
    	month = Integer.parseInt(JOptionPane.showInputDialog( "Enter a month in numeric form" ));
     
    	day = Integer.parseInt(JOptionPane.showInputDialog( "Enter a day in numeric form" ));
     
     	year = Integer.parseInt(JOptionPane.showInputDialog( "Enter a year in numeric form (2 digits only)"));
     
    	int goodYear =  month * day * year;
     
    	int magic = goodYear;
     
     
    	if ( (goodYear) == (magic) )
    	{
    		JOptionPane.showMessageDialog(null, " This date is magic " );
    	}
    	if ( (goodYear)(magic))
    	{
    		JOptionPane.showMessageDialog(null, " This date is not magic");
    	}
     
    	}
    }


    the problem is in the first part of the code as a comment.
    i am having problems with this part below =


     
    	int goodYear =  month * day * year;
     
    	int magic = goodYear;
     
     
    	if ( (goodYear) == (magic) )
    	{
    		JOptionPane.showMessageDialog(null, " This date is magic " );
    	}
    	if ( (goodYear)!(magic))
    	{
    		JOptionPane.showMessageDialog(null, " This date is not magic");
    	}
     
    	}
    }

    on the second if i am trying to say that if good year doesn't equal magic that it should display the message below but idk how to do it. or if i am even doing the equation right.

    anny suggestions.


  2. #2
    Member Ganeprog's Avatar
    Join Date
    Jan 2014
    Location
    Chennai,India
    Posts
    80
    My Mood
    Love
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default Re: how to make an if say that it doesnt equal

    Hi,

    Yes it is wrong. You can use this for not equal !=. you can also use if..else statement. For more details study Relational operators .

    Thanks,

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: how to make an if say that it doesnt equal

    These two lines are not useful - at least not useful in helping your program accomplish the assignment:

    int goodYear = month * day * year;
    int magic = goodYear;

    Reread the assignment with those two lines in mind to discover how they should be changed. Hint: the second line is unnecessary, but there's more.

  4. #4
    Junior Member
    Join Date
    Feb 2014
    Location
    Finland
    Posts
    25
    My Mood
    Bored
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: how to make an if say that it doesnt equal

    Hello.

    I see GregBrannon and Ganeprog have already given you nudges to the right direction but more aid can't hurt right?

    int goodYear = month * day * year;
    int magic = goodYear;

    Might help if you try saying it out loud: "goodYear is month times day times year."
    On the next line you say "magic is goodYear".
    And after that you ask in the if-condition "is goodYear magic?".

    if ( (goodYear) == (magic) )
    {
    	JOptionPane.showMessageDialog(null, " This date is magic " );
    }

    The not-equal operator in Java is != as Ganeprog pointed out.
    You can google for "java oracle summary of operators" for a nice list of Java operators. I tried to link it here directly but apparently im not allowed.

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: how to make an if say that it doesnt equal

    @Wizand: Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers, including a few "house rules" that will make you a more confident user of this forum.

  6. #6
    Junior Member
    Join Date
    Jan 2014
    Posts
    19
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: how to make an if say that it doesnt equal

    so i am saying that good year is magic instead of saying if good year equals magic.

    i am still very lost.

    so i don't need the int good year equation or the following statement or just the magic one

  7. #7
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: how to make an if say that it doesnt equal

    What makes a good year good? What makes a magic year?

  8. #8
    Junior Member
    Join Date
    Feb 2014
    Location
    Finland
    Posts
    25
    My Mood
    Bored
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: how to make an if say that it doesnt equal

    Quote Originally Posted by kittykat0953 View Post
    so i am saying that good year is magic instead of saying if good year equals magic.

    i am still very lost.

    so i don't need the int good year equation or the following statement or just the magic one
    Try not to lose the context in between the rows. Your equation "int magic = goodYear" means you are inserting the value of goodYear to the magic.
    Right after this you compare if magic equals to goodYear. This is always true, right? Since you just stated that magic is goodYear.

Similar Threads

  1. overwritten equal method does not work
    By justme1 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 7th, 2013, 11:14 AM
  2. How do i make two equations have to be equal?
    By jamesR in forum Java Theory & Questions
    Replies: 2
    Last Post: October 3rd, 2012, 12:10 AM
  3. Help writing if statement for two equal arrays
    By tuathan in forum Loops & Control Statements
    Replies: 1
    Last Post: June 29th, 2012, 09:57 AM
  4. Why does this equal that?
    By colerelm in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 27th, 2011, 06:20 PM
  5. While JOptionPane equal Yes????
    By maximus20895 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 20th, 2010, 08:57 PM