Results 1 to 4 of 4
  1. #1
    LasseA is offline Member
    Join Date
    Oct 2012
    Posts
    29
    Rep Power
    0

    Default if/else test if y is a multiple of z

    This is a self-check exercise from my Java book.
    Given that two ints "y" and "z", is already declared.
    How do I test if y is a multiple of z?

    //e. y is a multiple of z.
    if (z == ) {
    System.out.println("Correct");
    }
    else {
    System.out.println("False");
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,005
    Blog Entries
    7
    Rep Power
    20

    Default Re: if/else test if y is a multiple of z

    Check your textbook and read what the % (modulo) operator does.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    LasseA is offline Member
    Join Date
    Oct 2012
    Posts
    29
    Rep Power
    0

    Default Re: if/else test if y is a multiple of z

    Thanks, Edit: finally got it, and obviously it was more easy than I thougt y%z == 0.
    Last edited by LasseA; 11-10-2012 at 04:37 PM.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,005
    Blog Entries
    7
    Rep Power
    20

    Default Re: if/else test if y is a multiple of z

    Yep, that's it, except if z == 0

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 4
    Last Post: 04-27-2012, 09:43 AM
  2. One process open multiple threads on multiple CPUs
    By kfcnhl in forum Threads and Synchronization
    Replies: 2
    Last Post: 12-12-2011, 08:27 AM
  3. multiple Data from Jsp that having same name of multiple input tage to servlet
    By rahul9323.2007@gmail.com in forum Advanced Java
    Replies: 0
    Last Post: 07-29-2011, 01:00 PM
  4. Running multiple threads on multiple CPU cores?
    By Dosta in forum Threads and Synchronization
    Replies: 2
    Last Post: 09-19-2010, 03:48 PM
  5. Replies: 0
    Last Post: 04-05-2008, 12:38 AM

Posting Permissions

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