Results 1 to 5 of 5
  1. #1
    magicmike954 is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Help with simple program...2 week of java

    it says "Write a program that reads two double values and prints "identical" if they are the same value, "different" if they aren't. Name your class P1. Do not prompt for input; just read it. Do not print anything other than either "identical" or "different" (i.e., no extra text)."


    I did this:

    Why cant i do this:?

    class P1 {
    public static void main(String[] args){


    double d = 20;
    double e = 30;

    if(d == e)
    System.out.println("Identical");

    else if (d != e)
    System.out.println("Different");


    }
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Help with simple program...2 week of java

    What happened?

    Did the code compile? If not and you can't understand the compiler's messages, post them.

    If it did compile but did not do what you expected when you ran it, describe the behaviour you observed when you ran the program. Also it would be a good idea to say how (what commands) you used to compile and run the program.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Help with simple program...2 week of java

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    magicmike954 is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Re: Help with simple program...2 week of java

    it says "Write a program that reads two double values and prints "identical" if they are the same value, "different" if they aren't. Name your class P1. Do not prompt for input; just read it. Do not print anything other than either "identical" or "different" (i.e., no extra text)."

    This is all dont in Codelab, it is a form of software to help practice coding in java.

    Why wont this compile, error message reads:The input values were 24.7 and 94.2
    you should have printed "Different"
    your code had an error while execution


    Java Code:
    class P1 {
    public static void main(String[] args){
    
    
    double d = 20;
    double e = 30;
    
    if(d == e)
    System.out.println("Identical");
    
    else if (d != e)
    System.out.println("Different");
    
    
    }
    }

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Help with simple program...2 week of java

    The input values were 24.7 and 94.2
    This suggests to me that these values were supplied by the runtime when your program was tested. In other words, instead of assigning your own values to d and e you should get these values from the args array.

    Have you learnt about how to use that args array? If not, I suppose "reads two double values" could mean something else.

    -----

    It's a pity the instructions weren't clearer... Also whoeever wrote them needs to be shot - "different" isn't "Different": they're DiFfErEnT. And a trailing newline counts as "extra text" if anything does. Precision in expressing what a program does isn't an optional extra that can be put off until you are writing something complex like software to crash a spacecraft into the surface of Mars or whatever.

Similar Threads

  1. Can someone please help me with this simple java program???
    By moondancer3030 in forum New To Java
    Replies: 6
    Last Post: 06-22-2012, 10:47 AM
  2. Simple java program help.
    By CGHMN in forum New To Java
    Replies: 35
    Last Post: 07-15-2011, 12:31 PM
  3. Simple java program, need help
    By cliffh in forum New To Java
    Replies: 1
    Last Post: 10-21-2010, 03:32 AM
  4. Simple Java program
    By Rolle in forum New To Java
    Replies: 3
    Last Post: 10-26-2009, 04:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •