Reference no: EM131444742
Lab Project: The while Loop
Lab 1
Loops provide a mechanism for repeating a block of code called the loop body. We begin this lab by experimenting with while loops, the simplest form of loop code. Many loops are controlled with a single variable, which we will refer to as the loop control variable or the loop index.
Consider the code below. What is the output the program produces? Try changing the assigned value (6) of the limit variable to various integer values (e.g., 10, 100, 0, -10). What happens?
/**
A simple program that prints a loop control variable.
*/
public class SimpleLoop
{
public static void main(String[] args)
{
inti = 0;
int limit = 6;
while (i< limit)
{
System.out.println("i = " + i);
i++;
}
}
}
Lab 2
Consider the code below again. What happens if you comment out the line that increments i (line 13)? Will the program ever stop looping?
/**
A simple program that prints a loop control variable.
*/
public class SimpleLoop
{
public static void main(String[] args)
{
inti = 0;
int limit = 6;
while (i< limit)
{
System.out.println("i = " + i);
i++; // line 13
}
}
}
Lab 3
Manipulating the loop control variable is a critical skill in learning to write code with loops. Modify the program in Lab 1 so that it produces the following output:
i = 6
i = 8
i = 10
i = 12
i = 14
i = 16
i = 18
...
i = 98
What Do I Hand In?
Once you are done, submit your answers for Lab 1 and Lab 2, and upload the completed source code file (i.e., .java file) for Lab 3.
Creating forensic system case file for analyzing evidence
: Creating a Forensic System Case File for Analyzing Forensic Evidence - Create a new digital forensic case file using a forensic application and Document a new digital forensic case with digital evidence submitted to the newly created case file.
|
What is the most common housing pricing strategy
: REE 6147 - Spring 2017 Course Exam. According to Table 2, what is the most common housing pricing strategy employed in the market? What is the second most common pricing strategy
|
Presidential candidates are popular in area
: Suppose you are designing and conducting a poll to see which of the presidential candidates are popular in your area.
|
Evaluate the organizations productivity
: In the Middleboro Physician Care Services, Inc. case, you are asked to examine the operations of an ambulatory, non-emergent care clinic which treats private and occupational health patients and provides services which do not include continuing o..
|
Provide a mechanism for repeating a block of code
: CPS 150- Loops provide a mechanism for repeating a block of code called the loop body. We begin this lab by experimenting with while loops, the simplest form of loop code.
|
What is the cointegrating coefficient
: One version of the expectations theory of the term structure of interest rates holds that a long-term rate equals the average of the expected values of short-term interest rates into the future, plus a term premium that is 1(0).
|
What is the probability that a randomly selected dropout
: According to a recent study,9.3 % of high school dropouts are 16- to 17-year-olds. In addition,6.5 % of high school dropouts are white16- to17-year-olds. What is the probability that a randomly selected dropout is white, given that he or she is 16..
|
Depreciation expense on the income statement
: When you buy a vehicle for dollar 10,000 dollars, on the balance sheet you would reduce cash by dollar 10,000 and increase Property, Plant & Equipment by dollar 10,000. What TWO adjustments would you need to make in your Balance Sheet to make it bal..
|
Compare to a population of candidate votes
: This would be an example of two mean comparison. In terms of the recent election, Gallup may take a sample and compare to a population of candidate votes (sample mean compared to a population mean).
|