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

  Explain how cookies are used to implement sessions

Describe a set of four methods that a queue would need to implement using a circular array and show the Java code to implement them if using an implementation given the outline definition below. Do not use any methods of the Collection classes.

  Write a program that establishes two savings accounts

Write a program that establishes two savings accounts with saver1 having account number 10002 with an initial balance of $2,000, and saver2 having account 10003 with an initial balance of $3,000

  Write the code and output result1 real cash register can

write the code and output result.1. real cash register can handle both bills and coins. design a single class that

  Design a java program that has two parallel arrays

Design a java program that has two parallel arrays: a string array named people that is initialized with the names of seven of your friends, and a string array named phoneNumbers that is initialized with your friends phone numbers.

  Program to calculate the discount amount and total

calculate the discount amount and total and format and display the results

  Calculate and display the loan amount to two decimal places

Calculate and display the loan amount to 2 decimal places. Call all the calculation methods (methods 2 - 4) to compute the three parts of the monthly mortgage payment, and save the results returned from each.

  Design the interface classes drawable rotatable and sounds

Design the interface classes Drawable, Rotatable, Resizable and Sounds. Compare and contrast abstract classes and interfaces. In what situations would you use an abstract class? in what situations would you use an interface?

  Write java codes to perform sentiment analysis

In this programming assignment, I am asked to write Java codes to perform Sentiment Analysis: classifying movie reviews as positive or negative

  Examine the clocktype class definition

Examine the ClockType class definition. How many attributes does it contain? Assume we have two classes and have instantiated an object from each class. How many copies of each class's attributes and methods exist in the instantiated objects?

  Write a public static method called sumdigits

Write a public static method called sumDigits that will return the sum of the digits within a string.

  What attributes would your class have

What attributes would your class have? What methods would your class have - In the HelloWorld program, what is "public" that appears on the line that defines the main method?

  Exception handling for validating the input.

The program needs to have built in Exception handling for validating the input.

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