English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutoriel de base Java

Contrôle de flux Java

Java tableau

Java orienté objet (I)

Java orienté objet (II)

Java orienté objet (III)

Gestion des exceptions Java

Java Liste (List)

Java Queue (file d'attente)

Java Map

Java Set

Java entrée/sortie (I/O)

Java Reader/Writer

Autres sujets Java

Programme Java pour calculer le quotient et le reste

Java complete list of examples

Dans ce programme, vous apprendrez à calculer le quotient et le reste à partir du dividend et du diviseur en Java.

Exemple : calcul du quotient et du reste

public class QuotientRemainder {
    public static void main(String[] args) {
        int dividend = 25, divisor = 4;
        int quotient = dividend / divisor;
        int remainder = dividend % divisor;
        System.out.println("Quotient = ", + quotient);
        System.out.println("Remainder = ", + remainder);
    }
}

When running the program, the output is:

Quotient = 6
Remainder = 1

In the above program, two numbers25(dividend)and4(divisor)are stored in two variables dividend and divisor respectively.

Now, to find the quotient, we use / operator divides dividend by divisor. Since both dividend and divisor are integers, the result will also be calculated as an integer.

So, mathematically25/4The result is6.25But since both operands are int, the variable quotient only stores6(integer part).

Similarly, to find the remainder, we use the % operator. Therefore, we will25/4The remainder (i.e.1)is stored in the integer variable remainder.

Finally, use the println() function to print the quotient and remainder on the screen.

Java complete list of examples