Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2004

Tip: Looking for answers? Try searching our database.

strange problem

Thread view: 
Danny Gopie - 29 Nov 2004 14:48 GMT
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);

               }

          }

      }
Andrew Thompson - 29 Nov 2004 14:52 GMT
>          if ( (h2 % h1) ==67); {

         if ( (h2 % h1) ==67) {

Lose the ';'.  That effectively ends the 'if'.

Signature

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

Danny Gopie - 29 Nov 2004 15:34 GMT
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");

               } }

}
Andrew Thompson - 29 Nov 2004 15:37 GMT
It seems I did not look closely enough at this first time..

> public class hele {
>        public static void main(String[] args) {
[quoted text clipped - 3 lines]
>            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.

Signature

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

Danny Gopie - 29 Nov 2004 15:46 GMT
Thanks, I changed all the doubles to int. but the problems remains,

what is the rpbolem here?

> It seems I did not look closely enough at this first time..
>
[quoted text clipped - 11 lines]
> And to follow Java naming conventions, 'hele' should be 'Hele'.
> It would also help to have more meaningful attribute names.
Mike B - 29 Nov 2004 16:13 GMT
> 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>
Signature

Mike B

Stefan Schulz - 29 Nov 2004 19:58 GMT
>     {
>      System.out.println(+ h2+ " is een veelvoud van" + h1);
>     }                   ^
                          |
                          +---- What does this lonely plus do here?

Signature

Whom the gods wish to destroy they first call promising.

Mike B - 30 Nov 2004 02:15 GMT
>>     {
>>      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.

Signature

Mike B



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.