78.1k views
1 vote
Which of the following segments is a proper way to call the method readData four times? Group of answer choices int i = 0; while (i < 4) { readData(); i = i + 1; } double k = 0.0; while (k != 4) { readData(); k = k + 1; } int i = 0; while (i <= 4) { readData(); i = i + 1; } int i = 0; while (i < 4) { readData(); }

User DeepSpace
by
6.4k points

1 Answer

2 votes

Answer:

int i = 0; while (i < 4) { readData(); i = i + 1; }

Explanation:

the above method is proper way to call the method readData four times because it will start from zero and will call readData until i=3, if i=4 it will stop calling readData.

double k = 0.0; while (k != 4) { readData(); k = k + 1; }

This is not the proper way to call readData four times because it will call readData only if k!=4 otherwise condition k!=4 will not be true and readData will not be called.

int i = 0; while (i <= 4) { readData(); i = i + 1; }

This is not the proper way to call readData four times because condition i<=4 will call readData five times starting from zero to 4.

int i = 0; while (i < 4) { readData(); }

This is not the proper way to call readData four times because it will call readData only one time i.e. value of is not incremented.

User Josh Bernfeld
by
7.0k points