KnowledgeBoat Logo

Computer Applications

Give the output of the following program segment:

int x[] = {4, 3, 7, 8, 9, 10};
int p = x.length;
int q = x[2] + x[5] * x[1];
System.out.println("p=" + p);
System.out.println("q=" + q);

Java

Java Arrays

16 Likes

Answer

p=6
q=37

Working

  1. x.length gives the number of elements in the array which in this case is 6
  2. x[2] + x[5] * x[1] ⇒ 7 + 10 * 3 ⇒ 7 + 30 ⇒ 37

Answered By

5 Likes