Please Print Your Name
Computer
{
- Write one loop that will print the integers in the following pattern. Print them vertically and do not include the commas. [5 points]
for (int i = 1; i <= 5; i++) {
System.out.println(i);
System.out.println(i * 2);
}
Variable temp
is created
for(int i = 0; i < 3; i++) {
// Loop content
}
- Hand trace the following loop and show every step. Show how the variables change as the loop executes. [5 points] Date:
for (int j = 0; j < 3; j++) {
temp += 2;
}
Loop A, start. i=0. 143, true. Loop occurs.
Loop B start.
j=0. j≤3, true. loop occurs. Temp now equals 3. j++; j now equals 1.
j=1. j≤3, true. Loop occurs. Temp now equals 5. j++; j now equals 2.
J=2. j<3, true. Loop occurs. Temp now equals 7. j++; j now equals 3.
j=3. j!<3, loop doesn't occur. To go Bend. i now equals 1
Loop A, start again. i=2. 143, true. Loop occurs.
Loop B start. j=0. j<3, true. Loop occurs. Temp now equals. j++; j now equals 1.
j=1. j²3, true. Loop starts. Temp now equals 11. j++; j now equals 2.
j=2. j<3, true. Loop occurs. Temp now equals 13. j++; j now equals 3.
j=3₁ j!<3, loop doesn't occur. Togo Bend. i now equals 2
Loop A, start again. i=2 143, true. Loop occurs.
Loop B start. j=0. j≤3, true. Loop occurs. Temp now equals 15. j++; j now equals 1.
j=1. j<3, true. Loop occurs. Temp now equals 17. j++; j now equals 2.
j=2. j<3, true. Loop occurs. Temp now equals 19. j++; j now equals 3.
j=3₁ j!<3, loop doesn't occur. Togo Bend. i now equals 3. i≤3 is false, loop and take end.
- Suppose we are looking for all of the periods in an article. The article is a String variable type, and your job is to count the number of periods. Write the code to count the periods in the article below. Notice that the article is not yet placed there, and the placeholder is shown instead. This is because your algorithm does not depend on the article. [5 points]
String article = "<some article will be placed here>";
int periodCount = 0;
for (int i = 0; i <= article.length(); i++) {
if (string.charAt(i) == ".") {
periodCount++;
}
}
System.out.print(periodCount + " periods in article.");
- What do the letters RAM stand for?
Random Access Memory
- What is an object in the Java programming language?
An instance of a class
- What is a method in the Java programming language?
A statement that performs a task
- What is the size of an integer in the Java programming language?
4 bytes, 32 bits
- What is the size of a boolean in the Java programming language?
1 bit (as in 0, false or 1, true)