Provide a mechanism for repeating a block of code

Assignment Help JAVA Programming
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.

Reference no: EM131444742

Questions Cloud

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).

Reviews

Write a Review

JAVA Programming Questions & Answers

  Hypothetical situation

Hypothetical Situation - A company lowers its price of an economy car a small amount   ($15,000 to $14,000) Sales go from 10,000 units to 50,000 units. Another company lowers its price on a luxury car a large amount ($80,000 to $40,000). Its sales go..

  What are some debugging techniques for javascript

What are some common programming errors? How can they be prevented? What is the try catch structure, how is it useful? What are some debugging techniques for JavaScript?

  Write a program to prepare the monthly charge account

Write a program to prepare the monthly charge account statement for a customer of CS CARD International, a credit card company. The program should take as input the previous balance on the account and the total amount of additional charges during the..

  Prepare a thread function to initialize int array

Prepare a thread function to initialize int array x so that each element receives its index in the array: x[i]=i, and each thread initializes its portion of the array.

  Java shape program console

Program is adequately documented. It's comments identifies its name, purpose, author and date. Throughout the code, comments and/or relevant component names should attempt to make the program understandable.

  Solve the currently very un-pc cigarette smokers problem

Write solution to solve the currently very un-PC"cigarette smokers problem" in java using Java threads, and monitors (using the "synchronized" keyword) (If it bothers your PC sensibilities, think of it at the Pot-smokers problem and then it is all pr..

  Write a separate method to handle this task

In this assignment you use an abstract class to represent a bank account and concrete classes to represent a checking account and a savings account - Your program must have the capability to convert inputs to and from integer cent amounts. Write a..

  Write a java application that prompts the user for input

Write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (these are two separate prompts for input values).

  Concepts of polymorphism

This lab introduces students to the concepts of polymorphism, early binding, late binding, abstract classes, and virtual class functions. This will be done in the context of performing calculations on basic geometrical shapes

  Price and quantity of an article

XYZ Supermarket wants a program that will prompt for the product code, pricing code, price and quantity of an article. Your program is then to calculate a discount rate according to the pricing code.

  Write a class named test scores

Write a class named TestScores.The class constructor should accept an array of test scores as an argument.The class should have a method that returns the average of the test scores.

  What is the purpose of the pivot value in quicksort

What is the purpose of the pivot value in quicksort and How did we first select it in the text, and what is wrong with that approach for choosing a pivot value?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd