java programming constructs 3 mis 3023 business programming concepts ii the university of tulsa...
TRANSCRIPT
![Page 1: Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ed35503460f94be350e/html5/thumbnails/1.jpg)
Java Programming Constructs 3
MIS 3023
Business Programming Concepts II
The University of Tulsa
Professor: Akhilesh Bajaj
All slides in this presentation ©Akhilesh Bajaj, 2006. All rights reserved
![Page 2: Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ed35503460f94be350e/html5/thumbnails/2.jpg)
Objectives
• Continue to understand programming constructs in Java:-the while loop-the do-while loop-the for loop
Look at the break statementLook at the continue statement
Let’s get started!
![Page 3: Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ed35503460f94be350e/html5/thumbnails/3.jpg)
Nesting for Loops
To get the above output, we can use:
![Page 4: Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ed35503460f94be350e/html5/thumbnails/4.jpg)
Nesting for Loops
A program that will list all the letters contained in a string and will also count the number of different letters.
![Page 5: Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ed35503460f94be350e/html5/thumbnails/5.jpg)
The break Statement Syntax:break;
• Breaks out of a loop or switch statement• If used in an if statement, then the if statement HAS to be in a loop or a switch, and the program will break out of that container loop or switch statement.
Can we write the above with a for loop?
![Page 6: Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ed35503460f94be350e/html5/thumbnails/6.jpg)
The break Statement
We can also create a labeled break, to break out of nested loops.
label_name:loop1 loop 2
loop3break label_name;
end loop3end loop2
end loop1
Will break out of all the loops and proceed with the next statement below the 3 labeled loops.See example of ListLetters.java
![Page 7: Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ed35503460f94be350e/html5/thumbnails/7.jpg)
The continue Statement Syntax:continue;
• Continues with the next iteration of the loop.
• See program ContinueDemo.java
• The continue statement can also refer to a label, if we want to continue the next iteration of an outer loop.
![Page 8: Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation](https://reader036.vdocument.in/reader036/viewer/2022082612/56649ed35503460f94be350e/html5/thumbnails/8.jpg)
Fun In Class Example
Write a program called
MultiplicationTable.java
that prints the multiplication table for a particular integer, input by the user, times 1 till times 12 of that integer.