In Java, using Modulus or mod operator we can get remainder of a division.
For example :
123 / 10 will would be 12.3 so 3 is remainder of this division.
so 123 % 10 would give us 3.
Use-cases :
1) check if given number odd/even by checking if it's perfectly divisible by 2 or not.
if(no % 2 == 0){
System.out.println("no is an even number").
}
2) Check if number is divisible by any other number.
if(no % 7 == 0){
System.out.println("no is divisible by 7").
}
3) Split number to get individual digits by using mod operator.
int digit = no % 10; // get last digit
no = no/10 ; // discard last digit.
digit = no % 10; // will give second last digit now.
In questa pagina del sito puoi guardare il video online Java Modulus Operator Tutorial - With Examples and Use-cases della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Code Zen 03 agosto 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 16,009 volte e gli è piaciuto 206 spettatori. Buona visione!