![Page 1: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/1.jpg)
Programming Methodology (1)
![Page 2: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/2.jpg)
Iteration
![Page 3: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/3.jpg)
Learning objectives
• explain the term iteration;
• repeat a section of code with a for loop;
• repeat a section of code with a while loop;
• repeat a section of code with a do...while loop;
• select the most appropriate loop for a particular task;
• explain the term input validation and write simple validation routines.
![Page 4: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/4.jpg)
When to use a loop?
![Page 5: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/5.jpg)
Display a square of stars (five by five) on the screen as follows:
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
System.out.println("*****");
System.out.println("*****");
System.out.println("*****");
System.out.println("*****");
System.out.println("*****");
REPEAT 5 times{
}System.out.println("*****");
![Page 6: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/6.jpg)
The ‘for’ loop
![Page 7: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/7.jpg)
for ( ; ; ){
}
start counter test counter change counter
// instruction(s) to be repeated go here
i = 1 i++i <= 5
System.out.println(“*****”);
int i;
![Page 8: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/8.jpg)
Variable Scope
![Page 9: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/9.jpg)
public static void main (String [] args){
}
if ( /* some test */){
}
int x;
int y;
x = 10;
System.out.print(x);
System.out.print(y);System.out.print(y);
y = x+1;
![Page 10: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/10.jpg)
for ( ; ; ){
}
i = 1 i++i <= 5
System.out.println(“*****”);
RUN*************************
i 123456int i;
int i = 1
![Page 11: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/11.jpg)
Different ways of using the loop counter
![Page 12: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/12.jpg)
for ( ; ; ){
}
i ++i <= 5
System.out.println(“*****”);
*****
***************
int i = 1
![Page 13: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/13.jpg)
for ( ; ; ){
}
i = i + 2i <= 5
System.out.println(“*****”);
*****
***************
int i = 1
![Page 14: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/14.jpg)
for ( ; ; ){
}
i = i + 2i <= 10
System.out.println(“*****”);
*****
***************
int i = 1
![Page 15: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/15.jpg)
for ( ; ; ){
}
i = i + 2i <= 10
System.out.println(“*****”);
RUN*************************
i 1357911
int i = 1
![Page 16: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/16.jpg)
for ( ; ; ){
}
start counter test counter change counter
// instruction(s) to be repeated go here
int i = 10 i--i >= 1
System.out.println( i );
RUN
109876
i 1098765
54321
43210
![Page 17: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/17.jpg)
The body of the loop
![Page 18: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/18.jpg)
for ( ; ; ){
}
i ++i <= 3
System.out.println(“First line”);
*****
int i = 1
![Page 19: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/19.jpg)
for ( ; ; ){
}
i ++i <= 3
System.out.println(“First line”);
*****
int i = 1
System.out.println(“Second line”);
First lineSecond lineFirst lineSecond lineFirst lineSecond line
![Page 20: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/20.jpg)
for ( ; ; ){
}
i --i >= 1
System.out.println( i );
*****
int i = 10
10987654321
![Page 21: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/21.jpg)
for ( ; ; ){
}
i --i >= 1
if ( i > 5 ){
System.out.println( i );}
int i = 10
109876
![Page 22: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/22.jpg)
Nested loops
![Page 23: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/23.jpg)
for (int i = 1; i <= 5; i++){
}
System.out.println("*****");
![Page 24: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/24.jpg)
for (int i = 1; i <= 5; i++){
}
System.out.print("*");
System.out.println( );
System.out.print("*");System.out.print("*");
System.out.print("*");System.out.print("*");
![Page 25: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/25.jpg)
for (int i = 1; i <= 5; i++){
}
for (int j = 1; j <= 5; j++){
} System.out.print("*");
System.out.println( );
![Page 26: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/26.jpg)
Allowing the user to fix the size of the square
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
![Page 27: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/27.jpg)
Allowing the user to fix the size of the square
* * *
* * *
* * *
![Page 28: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/28.jpg)
for (int i = 1; i <= 5 ; i++) { for (int j = 1; j <= 5 ; j++) {
System.out.print("*"); } System.out.println( );}
System.out.println("Size of square?");num = sc.nextInt();
num; i++)
num; j++)
![Page 29: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/29.jpg)
Running the program
Size of square?
8
* * * * * * * ** * * * * * * ** * * * * * * ** * * * * * * ** * * * * * * ** * * * * * * ** * * * * * * ** * * * * * * *
![Page 30: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/30.jpg)
Size of square?
3
* * ** * ** * *
Running the program
![Page 31: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/31.jpg)
Non-fixed repetitions
![Page 32: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/32.jpg)
The ‘while’ loop
![Page 33: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/33.jpg)
3422
![Page 34: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/34.jpg)
Error!
![Page 35: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/35.jpg)
7343
![Page 36: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/36.jpg)
Error!
![Page 37: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/37.jpg)
1234
![Page 38: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/38.jpg)
CASH
![Page 39: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/39.jpg)
System.out.print(“Enter PIN: ”);
pin = sc.nextInt( );
System.out.print(“Invalid PIN, please re-enter: ”);
pin = sc.nextInt( );
System.out.println(“Correct PIN, have some money! ”);
while ( ){
}
*/ test goes here */pin != 1234
RUN
Enter PIN: 1234
Correct PIN, have some money!
5555
4321
Correct PIN, have some money!
Invalid PIN, please re-enter:
Invalid PIN, please re-enter: 1234
![Page 40: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/40.jpg)
Input Validation
![Page 41: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/41.jpg)
import java.util.*;public class DisplayResult{ public static void main(String[] args) { int mark; Scanner sc = new Scanner (System.in); System.out.println("What exam mark did you get?"); mark = sc.nextInt(); if (mark >= 40) { System.out.println("Congratulations, you passed"); } else { System.out.println("I‘m sorry, but you failed"); } System.out.println("Good luck with your other exams"); }}
CHECK MARK HERE
![Page 42: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/42.jpg)
System.out.println("What exam mark did you get?");
mark = sc.nextInt( );
if (mark >= 40) { System.out.println("Congratulations, you passed");}else{ System.out.println("I‘m sorry, but you failed");}System.out.println("Good luck with your other exams");
CHECK MARK HERESystem.out.println(“Invalid mark: please re-enter“);mark = sc.nextInt( );
while ( )
{
}
mark > 100mark < 0 ||
![Page 43: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/43.jpg)
Sample Program Run
What exam mark did you get?
101
Invalid mark: please re-enter
-10
Invalid mark: please re-enter
10
I'm sorry, but you failed
Good luck with your other exams
![Page 44: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/44.jpg)
The ‘do…while’ loop
![Page 45: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/45.jpg)
// some code here
// some code here
// some code goes here
{
}
while ( /*test goes here*/ )do
;
![Page 46: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/46.jpg)
import java.util.*;
public class FindCost4{ public static void main(String[] args ) {
double price, tax;Scanner sc = new Scanner(System.in);
}}
// code for rest of program here
char reply;
System.out.print (“Enter another product (y/n)?: ”);reply = sc.next().charAt(0);
{
} while ( );
?
reply == ‘y’ reply == ‘Y’||
do
![Page 47: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/47.jpg)
Sample Program Run
*** Product Price Check ***Enter initial price: 50Enter tax rate: 10 Cost after tax = 55.0 Enter another product (y/n)?: y
*** Product Price Check ***Enter initial price: 70Enter tax rate: 5
Cost after tax = 73.5 Enter another product (y/n)?: n
![Page 48: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/48.jpg)
Menu Driven Programs
![Page 49: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/49.jpg)
*** Product Price Check ***
[1] Enter Price
[2] Enter tax
[3] Calculate Cost
[4] Quit
Enter choice [1-4]: 1
Enter initial price: 12.5
![Page 50: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/50.jpg)
*** Product Price Check ***
[1] Enter Price
[2] Enter tax
[3] Calculate Cost
[4] Quit
Enter choice [1-4]: 1
Enter initial price: 100
![Page 51: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/51.jpg)
*** Product Price Check ***
[1] Enter Price
[2] Enter tax
[3] Calculate Cost
[4] Quit
Enter choice [1-4]: 2
Enter tax rate: 12.5
![Page 52: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/52.jpg)
*** Product Price Check ***
[1] Enter Price
[2] Enter tax
[3] Calculate Cost
[4] Quit
Enter choice [1-4]: 3
Cost = 112.5
![Page 53: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/53.jpg)
*** Product Price Check ***
[1] Enter Price
[2] Enter tax
[3] Calculate Cost
[4] Quit
Enter choice [1-4]: 4
Goodbye!
![Page 54: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/54.jpg)
Menu Driven Timetable Program
![Page 55: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/55.jpg)
*** Lab Times ***
[1] TIME FOR GROUP A
[2] TIME FOR GROUP B
[3] TIME FOR GROUP C
[4] QUIT
Enter choice [1-4]: 2
1.OOp.m
![Page 56: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/56.jpg)
*** Lab Times ***
[1] TIME FOR GROUP A
[2] TIME FOR GROUP B
[3] TIME FOR GROUP C
[4] QUIT
Enter choice [1-4]: 5
Options 1-4 only!
![Page 57: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/57.jpg)
*** Lab Times ***
[1] TIME FOR GROUP A
[2] TIME FOR GROUP B
[3] TIME FOR GROUP C
[4] QUIT
Enter choice [1-4]: 1
10.OOa.m
![Page 58: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/58.jpg)
*** Lab Times ***
[1] TIME FOR GROUP A
[2] TIME FOR GROUP B
[3] TIME FOR GROUP C
[4] QUIT
Enter choice [1-4]: 3
11.00a.m
![Page 59: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/59.jpg)
*** Lab Times ***
[1] TIME FOR GROUP A
[2] TIME FOR GROUP B
[3] TIME FOR GROUP C
[4] QUIT
Enter choice [1-4]: 4
Goodbye
![Page 60: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/60.jpg)
// code to declare variables
System.out.println(“[1] TIME FOR GROUP A”);System.out.println(“[2] TIME FOR GROUP B”);System.out.println(“[3] TIME FOR GROUP C”);System.out.println(“[4] QUIT”);
System.out.print(“Enter choice [1-4]: “);
choice = sc.next().charAt(0);switch(choice){
}
case ‘1’:case ‘2’:case ‘3’:
default:
System.out.println(“10.00a.m”);System.out.println(“1.00p.m”);System.out.println(“11.00a.m”);
System.out.println(“Options 1-4 only!”);
{
} choice != ‘4’
case ‘4’: System.out.println(“Goodbye”);
// CODE TO DISPLAY MENU
// CODE TO ENTER CHOICE
// CODE TO PROCESS CHOICE
do
while( );
char choice;
break;break;
break;break;
![Page 61: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/61.jpg)
![Page 62: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/62.jpg)
public class IterationQ3
{
public static void main(String[] args)
{
for(int i=1; i<=10; i++)
{
if (i%2 == 0)
{
System.out.println(i);
}
}
}
}
2
4
6
8
10
1i = 234567891011
![Page 63: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/63.jpg)
Assignment
![Page 64: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/64.jpg)
Aaron’s Shop
Guitar (£100) - How many?:
![Page 65: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/65.jpg)
Aaron’s Shop
Guitar (£100) - How many?: 2
![Page 66: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/66.jpg)
Aaron’s Shop
Guitar (£100) - How many?: 2
Total cost required?
![Page 67: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/67.jpg)
Aaron’s Shop
Guitar (£100) - How many?: 2
Total cost required? n
![Page 68: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/68.jpg)
Aaron’s Shop
Guitar (£100) - How many?: 2
Total cost required? n
Piano (£900) - How many?:
![Page 69: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/69.jpg)
Aaron’s Shop
Guitar (£100) - How many?: 2
Total cost required? n
Piano (£900) - How many?: 1
![Page 70: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/70.jpg)
Aaron’s Shop
Guitar (£100) - How many?: 2
Total cost required? n
Piano (£900) - How many?: 1
Total cost required?
![Page 71: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/71.jpg)
Aaron’s Shop
Guitar (£100) - How many?: 2
Total cost required? n
Piano (£900) - How many?: 1
Total cost required? y
![Page 72: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/72.jpg)
Aaron’s Shop
Guitar (£100) - How many?: 2
Total cost required? n
Piano (£900) - How many?: 1
Total cost required? y
Total cost so far = £1100
![Page 73: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/73.jpg)
Aaron’s Shop
Guitar (£100) - How many?: 2
Total cost required? n
Piano (£900) - How many?: 1
Total cost required? y
Total cost so far = £1100
Mike (£45) - How many?:
![Page 74: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/74.jpg)
Aaron’s Shop
Guitar (£100) - How many?: 2
Total cost required? n
Piano (£900) - How many?: 1
Total cost required? y
Total cost so far = £1100
Mike (£45) - How many?: 0
![Page 75: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/75.jpg)
Using a for loop, write a program that displays a "6 times" multiplication table; the output should look like this:
1 6 = 62 6 = 123 6 = 184 6 = 245 6 = 306 6 = 367 6 = 428 6 = 489 6 = 54
10 6 = 6011 6 = 6612 6 = 72
![Page 76: Programming Methodology (1). Iteration Learning objectives explain the term iteration; repeat a section of code with a for loop; repeat a section of](https://reader035.vdocument.in/reader035/viewer/2022062511/551ae3bf55034606048b5a95/html5/thumbnails/76.jpg)
Using a for loop, write a program that displays a "6 times" multiplication table; the output should look like this:
1 6 = 62 6 = 123 6 = 184 6 = 245 6 = 306 6 = 367 6 = 428 6 = 489 6 = 54
10 6 = 6011 6 = 6612 6 = 72