Quick question..

Discussion in 'Programming' started by Buby, May 15, 2016.

  1. Hey spigot, just wonder how do I check if a number is divisible my another number.
     
  2. I haven't tested the following before, but probably it will help you:

    Code (Text):
           
    int firstNumber = 2000;
    int secondNumber = 8;

    if (firstNumber % secondNumber == 0) System.out.println(firstNumber + " is divisible by " + secondNumber);
     
     
  3. You can use the modular operator, %, and check two different inputs.

    Code (Text):

    int a = 10;
    int b = 5;

    if (a % b == 0)
    {
         .... /** is divisible */
    }