
Explanation of Solution
a.
Given statements:
//declare the variables and assign the values
int i = 0;
int j = 10;
int n = 0;
//check "i" is less than "j"
while(i < j)
{
//increment the value
i++;
//decrement the value
j--;
//increment the value
n++;
}
Trace table for the above loops:
i | j | n |
0 | 10 | 0 |
1 | 9 | 1 |
2 | 8 | 2 |
3 | 7 | 3 |
4 | 6 | 4 |
5 | 5 | 5 |
Explanation:
Here, the “i” value is “0”, “j” value is “10” and “n” value is “0”.
- In first iteration of “while” loop checks “i < j” which means “0 < 10”. The condition becomes true, so it increment the “i” value, i = 1, decrement the “j” value, j = 9 and also increment the “n”, n = 1...
Explanation of Solution
b.
Given statements:
//declare the variables and assign the values
int i = 0;
int j = 0;
int n = 0;
//check "i" is less than "10"
while(i < 10)
{
//increment the value
i++;
//calculate the "n" value
n = n + i + j;
//increment the value
j++;
}
Trace table for the above loops:
i | j | n |
0 | 0 | 1 |
1 | 1 | 4 |
2 | 2 | 9 |
3 | 3 | 16 |
4 | 4 | 25 |
5 | 5 | 36 |
6 | 6 | 49 |
7 | 7 | 64 |
8 | 8 | 81 |
9 | 9 | 100 |
Explanation:
Here, the “i” value is 0, “j” value is 0 and “n” value is 0.
- In first iteration of “while” loop checks “i < 10” which means “0 < 10”. The condition becomes true, so it increment the “i” value, i = 1, calculate “n” value which means (0 + 1 + 0 = 1) and also increment the “j”, j = 1.
- In second iteration of “while” loop checks “i < 10” which means “1 < 10”. The condition becomes true, so it increment the “i” value, i = 2, calculate “n” value which means (1+ 2 + 1 = 4) and also increment the “j”, j = 2.
- In third iteration of “while” loop checks “i < 10” which means “2 < 10”. The condition becomes true, so it increment the “i” value, i = 3, calculate “n” value which means (4+ 3 + 2 = 9) and also increment the “j”, j = 3.
- In fourth iteration of “while” loop checks “i < 10” which means “3 < 10”...
Explanation of Solution
c.
Given statements:
//declare the variables and assign the values
int i = 10;
int j = 0;
int n = 0;
//check "i" is greater than "0"
while(i > 0)
{
//decrement the value
i--;
//increment the value
j++;
//calculate the "n" value
n = n + i - j;
}
Trace table for the above loops:
i | j | n |
10 | 0 | 8 |
9 | 1 | 14 |
8 | 2 | 18 |
7 | 3 | 20 |
6 | 4 | 20 |
5 | 5 | 18 |
4 | 6 | 14 |
3 | 7 | 8 |
2 | 8 | 0 |
1 | 9 | -10 |
Explanation:
Here, the “i” value is 10, “j” value is 0 and “n” value is 0.
- In first iteration of “while” loop checks “i > 0” which means “10 > 0”. The condition becomes true, so it decrement the “i” value, i = 9, increment the “j”, j = 1 and calculate “n” value which means (0 + 9 - 1 = 8).
- In second iteration of “while” loop checks “i > 0” which means “9 > 0”. The condition becomes true, so it decrement the “i” value, i = 8, increment the “j”, j = 2 and calculate “n” value which means (8 + 8 - 2 = 14).
- In third iteration of “while” loop checks “i > 0” which means “8 > 0”. The condition becomes true, so it decrement the “i” value, i = 7, increment the “j”, j = 3 and calculate “n” value which means (14 + 7 - 3 = 18).
- In fourth iteration of “while” loop checks “i > 0” which means “7 > 0”...
Explanation of Solution
d.
Given statements:
//declare the variables and assign the values
int i = 0;
int j = 10;
int n = 0;
//check "i" is greater than "0"
while(i != j)
{
//increment the "i" by 2
i = i + 2;
//decrement the "j" by 2
j = j – 2;
//increment the value
n++;
}
Trace table for the above loops:
i | j | n |
0 | 10 | 0 |
2 | 8 | 1 |
4 | 6 | 2 |
6 | 4 | 3 |
8 | 2 | 4 |
... |

Want to see the full answer?
Check out a sample textbook solution
Chapter 6 Solutions
EBK BIG JAVA: EARLY OBJECTS, INTERACTIV
- MGMT SS STATS, an umbrella body that facilitates and serves various Social Security Organizations/Departments within the Caribbean territories, stood poised to meet the needs of its stakeholders by launching an online database. The database will provide members and the public access to the complete set of services that can (also) be initiated face-to-face, and it will provide managed, private, secure access to a repository of public and/or personal information. Ideally, the database will have basic details of pension plans recorded in the registry, member plan statistics, and cash inflows and outflows from pension funds.For example, insured persons accumulate contributions. Records for these persons will include information on the insured persons able to acquire various benefits once work is interrupted due to sickness, death, retirement, and maternity or employment injury. They will also include information on pensions such as invalidity, disability, and survivors that stem from one…arrow_forwardWhy all appvif i want to sign in its required phone number why not using google or apple its make me frustratedarrow_forwardWhy is the accuracy of time important in data visualizations? Detail a scenario from your professional experience in which time was structured poorly in a data visualization. How did this affect the understanding of the data presented? How do you think this error or oversight occurred?arrow_forward
- Write the KeanStudent class. The UML diagram of the class is represented below: KeanStudent - fullName: String - keanID: int -keanEmailAddress: String cellPhoneNumber: String + numberOfStudent: int + KeanStudent() + KeanStudent(fullName: String, keanID: int, keanEmailAddress: String, cellPhoneNumber: String) +getFullName(): String +setFullName(newFullName: String): void +getKeanIDO): int +getKeanEmailAddress(): String +getCellPhoneNumber(): String + setCellPhoneNumber(newCellPhoneNumber: String): void +toString(): String 1. Implement the KeanStudent class strictly according to its UML one-to-one (do not include anything extra, do not miss any data fields or methods) 2. Implement a StudentTest class to test the class KeanStudent you just created. • Create two KeanStudent objects using a no-args constructor and one from the constructor with all fields. o Print the contents of both objects. 。 Print numberOfStudent. 3. Add comments to your program (mark where data fields, constructors,…arrow_forwardMGMT SS STATS, an umbrella body that facilitates and serves various Social SecurityOrganizations/Departments within the Caribbean territories, stoodpoised to meet the needs of its stakeholders by launching an onlinedatabase at www.SSDCI.gov. The database will provide membersand the public access to the complete set of services that can (also)be initiated face-to-face, and it will provide managed, private, secure access to a repository ofpublic and/or personal information. Ideally, the database will have basic details of pensionplans recorded in the registry, member plan statistics, and cash inflows and outflows frompension funds.For example, insured persons accumulate contributions. Records for these persons will includeinformation on the insured persons able to acquire various benefits once work is interrupteddue to sickness, death, retirement, and maternity or employment injury. They will also includeinformation on pensions such as invalidity, disability, and survivors that stem from…arrow_forward(c) Consider the following set of processes: Process ID Arrival Time Priority Burst Time A 2 3 100 B 6 C 10 1 (highest) 2 40 80 D 16 4 (lowest) 20arrow_forward
- (3c) In the following resource allocation graph, is the state a deadlocked one? If so which ones are deadlocked? (3 points) Resource allocation graph. R₁ = Resource, P = process. R1 R3 R3 7arrow_forwardWhat resources are used when a thread is created? How do these differ from those used when a process is created?arrow_forward(c) Consider the following set of processes: Process ID Arrival Time Priority Burst Time A 2 3 100 B 6 C 10 1 (highest) 2 40 80 D 16 4 (lowest) 20arrow_forward
- (3e) Test-and-Set. The Test-and-Set instruction is used in hardware to achieve synchronization. It can be defined in the following way: function Test-and-Set (var target: boolean): boolean; begin Test-and-Set:= target; target := true; end; Now show how the Test-and-Set instruction can be used to protect a critical region and hence achieve mutual exclusion (do not worry about satisfying the bounded waiting condition). (8 points) repeatarrow_forwardConsider a system with three smoker processes and one agent process. Each smoker continuously rolls a cigarette and then smokes it. But to roll and smoke a cigarette, the smoker needs three ingredients: tobacco, paper and matches. One of the smoker processes has paper, another has tobacco and the third has the matches. The agent has an infinite supply of all three materials. The agent places two of the ingredients on the table. The smoker who has the remaining ingredient then makes and smokes a cigarette, signaling the agent on completion. The agent then puts out another two of the three ingredients, and the cycle repeats. Given below is a solution to the Cigarette-Smokers Problem. Give initial conditions for the semaphores as well as plausible values for the variables i & j and r & s, such that the agent and smokers are synchronized. Write a couple of sentences on why these initial conditions are necessary and sufficient. Solution: var a: array [0..2] of semaphore (initial condition =…arrow_forwardLevel-0 Diagram for this: A customer sends in an order form containing details of their order and their membership number. A check is made to verify that they are a member. When their order is verified, a check is made to validate that the items ordered are produced by the company. Next, the valid order is used to update the daily order file, and then used to create a shipping list and invoice, which are sent on to the Order Fulfilment System.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





