The prime number is int . It is necessary to determine whether it is divisible by 10 integers. Everything seems simple, but nothing comes to mind. Help me please.

  • four
    In all the answers you were absolutely advised to use the % operation to get the remainder of the division. But if it were not, then it would be possible to do so - if ((a / 10) * 10 == a) // да, чисто делится на 10 - avp

4 answers 4

Use for this kind of tasks the operator % , which returns the remainder of dividing the left value by the right value .

Example:

 number = 10; if(number%10==0) System.out.println("Число делится на 10"); 

    For this there is the operator "%", the result of which is the remainder of the division.

    With it, this problem is solved rather trivially:

     int a=15; if(a%10==0) //В нашем случае результатом будет 5, значит проверка не пройдет { //Делится на 10 целочисленно ... } else { //Не делится ... } 

      Here is a simple function to check. If it is divided, it returns true; otherwise, it returns false.

       public boolean byTen(int n){ return n % 10 == 0; } 

        You need to use the remainder of the division, which means that you need

         int number = 10; if (number % 10 == 0) { System.out.pritln(number); } 

        That is, learn to match)