JavaScript is required

Anh (Chị) hãy cho biết kết quả của đoạn lệnh sau là gì?

public class Test { public static void main(String[] args)

{ int k=0,n,dem,j=0;

while(j<3) {

k=8;

dem=0;

{

for(n=3;n<=k;n++)

{ if(k%n==0)

dem++;

}

if(dem==1) {

System.out.print(k+” “);

j++;

}

}

}

}

A.

Chương trình báo lỗi.

B.

2 3 5

C.

2 3 5 7 11

D.

3 4 5 7 11

Trả lời:

Đáp án đúng: A


The code iterates three times, checking if the number 8 has exactly one divisor between 3 and 8. The divisors of 8 in that range are 4 and 8. Since there are two divisors, nothing is printed.

Câu hỏi liên quan