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");
}
}
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.
Re: Help with simple program...2 week of java
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
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");
}
}
Re: Help with simple program...2 week of java
Quote:
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.