Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

int k=7; if (k%3 > 1) k=10; else k=5; // what k will be? int k=17; if (k%5 > 2 |

ID: 3835736 • Letter: I

Question

int k=7; if (k%3 > 1) k=10; else k=5; // what k will be?

int k=17; if (k%5 > 2 || k/5 > 2) k=10; else k=5; // what k will be?


for(i=0; i < 5; i++) { ... } // How many loops will be executed?

for(i = -5; i < -1; i++) { ... } // How many loops will be executed?

for(i= 10; i < 5; i=i-1) { ... } // How many loops will be executed?

int[ ] x = new int[10]; Random r = new Random(); x[1] = r.Next(100); // Explain these 3 statements


List pNames = new List {"nut","bolt","nail"}; // Explain these lines

class Room { public string RoomID { set; get; } ... }// Explain these lines


public Room ( ) { ... }// Explain these lines


public override string ToString( ) // Explain these lines

Room BU04A = new Room(); BU04A.RoomID = "BU 04A"; // Explain these lines

Explanation / Answer

int k=7; if (k%3 > 1) k=10; else k=5; // what k will be?

k will be 5 as k%3 is 1

int k=17; if (k%5 > 2 || k/5 > 2) k=10; else k=5; // what k will be?

k will be 10 as k/3 is 3 which is greater than 2


for(i=0; i < 5; i++) { ... } // How many loops will be executed?

loop will be execute 5 times, i = 0,1,2,3,4

for(i = -5; i < -1; i++) { ... } // How many loops will be executed?

Loop will be execute 4 times

-5,-4,-3,-2