Results 1 to 5 of 5
- 09-13-2012, 03:17 AM #1
Member
- Join Date
- Sep 2012
- Posts
- 2
- Rep Power
- 0
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");
}
}
- 09-13-2012, 03:30 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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.
- 09-13-2012, 03:42 AM #3
Re: Help with simple program...2 week of java
Forum Rules -- particularly the third paragraph
Guide For New Members
BB Code List - Java Programming Forum
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 09-13-2012, 03:50 AM #4
Member
- Join Date
- Sep 2012
- Posts
- 2
- Rep Power
- 0
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"); } }
- 09-13-2012, 05:30 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Re: Help with simple program...2 week of java
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.The input values were 24.7 and 94.2
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
-
Can someone please help me with this simple java program???
By moondancer3030 in forum New To JavaReplies: 6Last Post: 06-22-2012, 10:47 AM -
Simple java program help.
By CGHMN in forum New To JavaReplies: 35Last Post: 07-15-2011, 12:31 PM -
Simple java program, need help
By cliffh in forum New To JavaReplies: 1Last Post: 10-21-2010, 03:32 AM -
Simple Java program
By Rolle in forum New To JavaReplies: 3Last Post: 10-26-2009, 04:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks