Write a program that generates the following pattern:
1
12
123
1234
12345
Notice the following:
The program generates rows (lines)
The program generates columns (number of numbers)
For every row, it prints the corresponding numeric number, e.g., first row prints 1, second row prints 2, …, n row will print n, where n is any number.
Every time we have multiple variables that depend on each other, we need to consider the potential nested loop. A nested loop is a loop within another loop. In this case, let's create variables for the rows and columns
for(int row = 1; row <= 5; row++){
for(int col = 1; col <=row; col++){
System.out.print(col);
}
System.out.println();
}
AP CS A
[while Loop]
CON-2.H Compute statement execution counts and informal run-time comparison of iterative statements.
CON-2.H.1 A statement execution count indicates the number of times a statement is executed by the program.
[do-while Loop]
CON-2.C.1 Iteration statements change the flow of control by repeating a set of statements zero or more times until a condition is met.
[Random Numbers]
CON-1.D.4 The values returned from Math.random can be manipulated to produce a random int or double in a defined range
Explain the importance of algorithms in the problem-solving process.
Demonstrate how a problem may be solved by multiple algorithms, each with different properties.
Read a given program, and explain what it does
Trace the flow of control during the execution of a program (both correct and incorrect).
Use appropriate terminology to identity elements of a program (e.g., identifier, operator, operand)
Reading and explaining code
Basic concepts such as variables, primitive data types, expression evaluation, assignment, etc.