Single Choice Easy

QIf p is 20 and q is 4, what is the result of the expression p / q using integer division in Java?

ID: #20130 Arithmetic Operators in Java 116 views
Question Info
#20130Q ID
EasyDifficulty
Arithmetic Operators in JavaTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 5
  • B 4.0
  • C 5.0
  • D 4
Correct Answer

Explanation

When performing integer division in Java (/ with integer operands), the result is an integer, and any remainder is truncated. In this case, 20 / 4 equals 5.


public class IntegerDivisionExample {
    public static void main(String[] args) {
        // Define the values of p and q
        int p = 20;
        int q = 4;

        // Perform integer division (p / q)
        int result = p / q;

        // Display the result
        System.out.println("Result of p / q using integer division: " + result);
    }
}

When you run this program, it will output:


Result of p / q using integer division: 5

This is because integer division in Java truncates the fractional part and returns the quotient as an integer. In this case, 20 / 4 results in 5.

Share This Question

Challenge a friend or share with your study group.