SlideShare a Scribd company logo
Core Java Training
Practice Session
Page 1Classification: Restricted
Agenda
• Practice session
• Object Oriented Programming (OOPs) Concepts
Page 2Classification: Restricted
Nested for loops
• A loop placed inside another loop.
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 10; j++) {
System.out.print("*");
}
System.out.println(); // to end the line
}
• Output:
**********
**********
**********
**********
**********
• The outer loop repeats 5 times; the inner one 10 times.
• "sets and reps" exercise analogy
Page 3Classification: Restricted
What is the output?
Page 4Classification: Restricted
What is the output?
Page 5Classification: Restricted
What is the output?
Page 6Classification: Restricted
What is the output?
Page 7Classification: Restricted
What is the output?
Page 8Classification: Restricted
What is the output?
• Infinite Loop
Page 9Classification: Restricted
What is the output?
Page 10Classification: Restricted
What is the output?
• Infinite Loop
Page 11Classification: Restricted
Generating Complex Line Outputs…
• What nested for loops produce the following output?
• We must build multiple complex lines of output using:
• an outer "vertical" loop for each of the lines
• inner "horizontal" loop(s) for the patterns within each line
Page 12Classification: Restricted
Outer and Inner Loop
• First write the outer loop, from 1 to the number of lines.
• Now look at the line contents. Each line has a pattern:
• some dots (0 dots on the last line), then a number
• Observation: the number of dots is related to the line number.
Page 13Classification: Restricted
Mapping loops to numbers
• What statement in the body would cause the loop to print:
4 7 10 13 16
Page 14Classification: Restricted
Mapping loops to numbers
• What statement in the body would cause the loop to print:
4 7 10 13 16
Page 15Classification: Restricted
Loop tables
• What statement in the body would cause the loop to print:
2 7 12 17 22
• To see patterns, make a table of count and the numbers.
– Each time count goes up by 1, the number should go up by 5.
– But count * 5 is too great by 3, so we subtract 3.
Page 16Classification: Restricted
Nested for loop exercise
• Make a table to represent any patterns on each line.
Page 17Classification: Restricted
What is the output?
Page 18Classification: Restricted
What is the output?
Page 19Classification: Restricted
Write a program to…
Page 20Classification: Restricted
Solution
Page 21Classification: Restricted
Topics to be covered in next session
• Object Oriented Concepts
• Introduction to OO Analysis and Design
Page 22Classification: Restricted
Thank You!

More Related Content

PPSX
Strings in Java
PPTX
Session 06 - Practice Session
PPTX
Session 03 - Elements of Java Language
PPTX
Session 04 - Arrays in Java
PPSX
Arrays in Java
PPTX
Session 05 - Strings in Java
PPTX
Session 10 - OOP with Java - Abstract Classes and Interfaces
PPTX
Session 08 - OOP with Java - continued
Strings in Java
Session 06 - Practice Session
Session 03 - Elements of Java Language
Session 04 - Arrays in Java
Arrays in Java
Session 05 - Strings in Java
Session 10 - OOP with Java - Abstract Classes and Interfaces
Session 08 - OOP with Java - continued

What's hot (6)

PDF
From DOT to Dotty
PDF
Implementing Higher-Kinded Types in Dotty
PPTX
Session 18 - Review Session and Attending Java Interviews
PPSX
Review Session - Part -2
PPTX
Session 07 - Intro to Object Oriented Programming with Java
PPTX
Session 14 - Object Class
From DOT to Dotty
Implementing Higher-Kinded Types in Dotty
Session 18 - Review Session and Attending Java Interviews
Review Session - Part -2
Session 07 - Intro to Object Oriented Programming with Java
Session 14 - Object Class
Ad

Similar to Practice Session (20)

PPT
C++ CH3-P2 using c++ in all other parts.ppt
PPT
C++ control loops
PDF
DSA 103 Object Oriented Programming :: Week 3
PPT
Chapter 5 Looping
PDF
Chapter_05HGUYUYGUYGUTFTIVVGUTFGIHGHYIYUIGY
PPT
PPTX
06.Loops
PPTX
for loop in java
PPT
Iteration
PPTX
Nested loops
PPTX
Cs1123 6 loops
PDF
04-Looping( For , while and do while looping) .pdf
DOCX
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
PPT
Java Programming: Loops
PPTX
12-Lec - Repetition For Loop.pptx
PDF
Cse115 lecture08repetitionstructures part02
PDF
Programming Fundamentals presentation slide
C++ CH3-P2 using c++ in all other parts.ppt
C++ control loops
DSA 103 Object Oriented Programming :: Week 3
Chapter 5 Looping
Chapter_05HGUYUYGUYGUTFTIVVGUTFGIHGHYIYUIGY
06.Loops
for loop in java
Iteration
Nested loops
Cs1123 6 loops
04-Looping( For , while and do while looping) .pdf
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
Java Programming: Loops
12-Lec - Repetition For Loop.pptx
Cse115 lecture08repetitionstructures part02
Programming Fundamentals presentation slide
Ad

More from Hitesh-Java (20)

PPSX
Spring - Part 4 - Spring MVC
PPSX
Spring - Part 3 - AOP
PPSX
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
PPSX
Spring - Part 1 - IoC, Di and Beans
PPSX
JSP - Part 2 (Final)
PPSX
JSP - Part 1
PPSX
Struts 2 - Hibernate Integration
PPSX
Struts 2 - Introduction
PPSX
Hibernate - Part 2
PPSX
Hibernate - Part 1
PPSX
JDBC Part - 2
PPSX
PPSX
Java IO, Serialization
PPSX
Inner Classes
PPSX
Collections - Maps
PPSX
Review Session and Attending Java Interviews
PPSX
Collections - Lists, Sets
PPSX
Collections - Sorting, Comparing Basics
PPSX
Collections - Array List
PPSX
Object Class
Spring - Part 4 - Spring MVC
Spring - Part 3 - AOP
Spring - Part 2 - Autowiring, Annotations, Java based Configuration - slides
Spring - Part 1 - IoC, Di and Beans
JSP - Part 2 (Final)
JSP - Part 1
Struts 2 - Hibernate Integration
Struts 2 - Introduction
Hibernate - Part 2
Hibernate - Part 1
JDBC Part - 2
Java IO, Serialization
Inner Classes
Collections - Maps
Review Session and Attending Java Interviews
Collections - Lists, Sets
Collections - Sorting, Comparing Basics
Collections - Array List
Object Class

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Spectroscopy.pptx food analysis technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation theory and applications.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Electronic commerce courselecture one. Pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Empathic Computing: Creating Shared Understanding
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Review of recent advances in non-invasive hemoglobin estimation
Spectroscopy.pptx food analysis technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MIND Revenue Release Quarter 2 2025 Press Release
Advanced methodologies resolving dimensionality complications for autism neur...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Unlocking AI with Model Context Protocol (MCP)
Encapsulation theory and applications.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
sap open course for s4hana steps from ECC to s4
Electronic commerce courselecture one. Pdf
Programs and apps: productivity, graphics, security and other tools
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
“AI and Expert System Decision Support & Business Intelligence Systems”
Empathic Computing: Creating Shared Understanding

Practice Session