| View previous topic :: View next topic |
| Author |
Message |
Danny Gopie Guest
|
Posted: Mon Nov 29, 2004 2:48 pm Post subject: strange problem |
|
|
Hello, I dont understand why it print these line((+ h1+ " is een veelvous
van" + h2), becouse the condition is not true. Whatever the values are, it
always print the line.
public class hele {
public static void main(String[] args) {
double h1 = 1;
double h2 = 3;
double p1 = 9;
double p2 = 8;
if ( (h2 % h1) ==67); {
System.out.println(+ h1+ " is een veelvous van" + h2);
}
}
}
|
|
| Back to top |
|
 |
Andrew Thompson Guest
|
|
| Back to top |
|
 |
Danny Gopie Guest
|
Posted: Mon Nov 29, 2004 3:34 pm Post subject: Re: strange problem |
|
|
thanks, but it still doesnt work as it should, my question is
a = 0.0 and still it prints out these last 2 lines why??
I have the complete script here
public class hele {
public static void main(String[] args) {
double h1 = 3;
double h2 = 6;
double p1 = 5;
double p2 = 8;
double a = h2 % h1;
System.out.println(a);
if ( (h2 % h1) ==0.0) {
System.out.println(+ h2+ " is een veelvoud van" + h1);
} if ( (h1 % h2) ==0.0) {
System.out.println(+ h1+ " is een veelvoud van" + h2);
} if (p1 % p2 ==0.0 ){
System.out.println(+ p1+ " is een veelvoud van" + p2);
} if (p2 % p1 ==0.0 ){
System.out.println(+ p2+ " is een veelvoud van" + p1);
////// LAST 2 LINES WHICH SHOULDN;t be printed
}if ( h1 % h2 !=0.0|| h2 % h1 !=0.0){
System.out.println("de hele getallen zijn geen veelvoud van
mekaar");
} if ((p1 % p2 !=0.0) || (p2 % p1 !=0.0) ){
System.out.println("de positieve getallen zijn geen
veelvoud van mekaar");
} }
}
|
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Mon Nov 29, 2004 3:37 pm Post subject: Re: strange problem |
|
|
On Mon, 29 Nov 2004 15:48:34 +0100, Danny Gopie wrote:
It seems I did not look closely enough at this first time..
| Quote: | public class hele {
public static void main(String[] args) {
double h1 = 1;
double h2 = 3;
double p1 = 9;
double p2 = 8;
|
Comparing doubles for equality will usually fail, as..
<http://www.xdweb.net/~dibblego/java/faq/answers.html#Q41>
And to follow Java naming conventions, 'hele' should be 'Hele'.
It would also help to have more meaningful attribute names.
--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
|
|
| Back to top |
|
 |
Danny Gopie Guest
|
Posted: Mon Nov 29, 2004 3:46 pm Post subject: Re: strange problem |
|
|
Thanks, I changed all the doubles to int. but the problems remains,
what is the rpbolem here?
"Andrew Thompson" <SeeMySites (AT) www (DOT) invalid> schreef in bericht
news:cln56ltilhnc.gzec0s8doxr9.dlg (AT) 40tude (DOT) net...
|
|
| Back to top |
|
 |
Mike B Guest
|
Posted: Mon Nov 29, 2004 4:13 pm Post subject: Re: strange problem |
|
|
Danny Gopie <ouygiytf (AT) jhgvkuy (DOT) nl> wrote:
| Quote: | Thanks, I changed all the doubles to int. but the problems remains,
what is the rpbolem here?
|
Try running this and see if you can see what the "problem" may be.
<sscce> public class Hele {
public static void main(String[] args) {
int h1 = 3;
int h2 = 6;
int p1 = 5;
int p2 = 8;
System.out.println(h2 % h1);
if ( (h2 % h1) ==0)
{
System.out.println(+ h2+ " is een veelvoud van" + h1);
}
if ( (h1 % h2) ==0)
{
System.out.println(+ h1+ " is een veelvoud van" + h2);
}
if (p1 % p2 ==0 )
{
System.out.println(+ p1+ " is een veelvoud van" + p2);
}
if (p2 % p1 ==0 )
{
System.out.println(+ p2+ " is een veelvoud van" + p1);
}
////// LAST 2 LINES WHICH SHOULDN;t be printed
if ( h1 % h2 !=0|| h2 % h1 !=0)
{
System.out.println(h1 % h2 + " OR " + h2 % h1);
System.out.println("de hele getallen zijn geen veelvoud van mekaar");
}
if ((p1 % p2 !=0) || (p2 % p1 !=0) )
{
System.out.println(p1 % p2 + " OR " + p2 % p1);
System.out.println("de positieve getallen zijn geen veelvoud van
mekaar");
}
}
}
</sscce>
--
Mike B
|
|
| Back to top |
|
 |
Stefan Schulz Guest
|
Posted: Mon Nov 29, 2004 7:58 pm Post subject: Re: strange problem |
|
|
On Mon, 29 Nov 2004 10:13:53 -0600, Mike B
<mrcics2000-news-nomail (AT) nomail (DOT) yahoo.com> wrote:
| Quote: | {
System.out.println(+ h2+ " is een veelvoud van" + h1);
} ^
+---- What does this lonely plus do here? |
--
Whom the gods wish to destroy they first call promising.
|
|
| Back to top |
|
 |
Mike B Guest
|
Posted: Tue Nov 30, 2004 2:15 am Post subject: Re: strange problem |
|
|
Stefan Schulz <terra (AT) spacetime (DOT) de> wrote:
| Quote: | On Mon, 29 Nov 2004 10:13:53 -0600, Mike B
[email]mrcics2000-news-nomail (AT) nomail (DOT) yahoo.com[/email]> wrote:
{
System.out.println(+ h2+ " is een veelvoud van" + h1);
} ^
|
+---- What does this lonely plus do here?
|
Uh, can I plead haste? I was in a hurry and didn't look at the OP's code too
finely. He has all his printlns like that. I just didn't clean it up.
--
Mike B
|
|
| Back to top |
|
 |
|