Solved Math Operations - Division

Discussion in 'Plugin Development' started by xXSilentYoshiXx, Jul 3, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    xXSilentYoshiXx

    How can I find out if #1 can be divisible by #2?

    Example:
    Code:
    Integer one = 60;
    Integer two = 30;
     
    if (60 / 30 == true) {
        System.print.ln("Test complete");
    }
    That code above doesn't work. How do I make it so that I can found out if a number can be divisible by another one?
     
  2. Offline

    Shzylo

    use the modulus '%' it finds the remainder of 2 numbers divided.

    if (60 % 30 == 0) {
    System.out.println("60 is divisible by 30.");
    }
     
  3. Offline

    microgeek

    Use the modulus operator(%).
    Code:java
    1.  
    2. if(60 % 30 == 0) {
    3. //if the remainder of 60 / 30 is 0
    4. }
    5.  
     
  4. Offline

    xXSilentYoshiXx

    No, that's not really what I want.

    My explanation: If #1 can be divisible by #2, then _____.

    What I'm trying to do: Countdown using a timer, and while #1 can be #2, then _____.

    Actually, this is the right forum, Faith. It's just that the top was an EXAMPLE, not what I'm really trying to do. :p

    ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  5. Offline

    Shzylo

    That is what the modulus is doing.
     
  6. Offline

    microgeek

    Using the modulus operator will do this.
    Code:java
    1.  
    2. if(60 % 30 == 0) {
    3. //if the remainder of 60 / 30 is 0
    4. }
    5. //60 CAN be 30
    6. //60 / 2 = 30(with 0 remainder, hence why the modulus operation works)
    7.  


    Second time you ninja'd me! :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  7. Offline

    xXSilentYoshiXx

    I don't think so... It seems like it's checking if 60 divided by 30 is 0 XD
     
  8. Offline

    Shzylo

    if it is 0 that means 60 is divisible by 30.
     
  9. Offline

    xXSilentYoshiXx

    Oh, I get it now. Thanks, everyone. :)
     
Thread Status:
Not open for further replies.

Share This Page