SlideShare a Scribd company logo
1
In the name of Allah
Ghalib University
Computer Science Faculty
General Department
Advanced Java
Lecture Title
Lecture #2 Practical Work
Examples
Subject: Advanced Java
Instructor: Mohammad Dawood Saddiqi
Date: Saturday, July 5, 2025
List of Contents
• At First Some Questions
• While Loop
• The do-while Loop
• The for Loop
• Methods
• Arrays
• Summary
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 2
At First Some Questions
• What is Loop?
• What is Loop body?
• What is iteration of a Loop?
• Can you convert a for loop to a while loop?
• What is Method?
• What is Array?
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 3
While Loop
Example #1
• We want to develop a program that prompts the user to enter an
answer for a question on addition of two single digits. Using a loop,
you can rewrite the program to let the user repeatedly enter a new
answer until it is correct.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 4
Cont.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 5
Cont.
Example #2
• The problem is to guess what number a computer has in mind. You
will write a program that randomly generates an integer between 0 and
100, inclusive. The program prompts the user to enter a number
continuously until the number matches the randomly generated
number. For each user input, the program tells the user whether the
input is too low or too high, so the user can make the next guess
intelligently. Here is a sample run:
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 6
Cont.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 7
The do-while Loop
Example #3
• Suppose the input is 2 3 4 5 0. What is the output of the following
code?
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 8
The for Loop
Example #4
• Suppose the input is 2 3 4 5 0. What is the output of the following
code?
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 9
Cont.
Example #5
• Write a program that uses nested for loops to display a multiplication
table.
• Like this:
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 10
Cont.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 11
The Answer:
Methods
Example #6
• Redesign the printGrade
method to return a value.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 12
Cont.
• The answer:
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 13
Cont.
Example #7
• Identify and correct the errors in the following program:
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 14
Arrays
Example #8
• Initializing arrays with input values: The following loop
initializes the array myList with user input values.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 15
Cont.
Example #9
• Initializing arrays with random values: The following loop
initializes the array myList with random values between 0.0 and
100.0, but less than 100.0.
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 16
Cont.
Example #10
• Displaying arrays: To print an array, you have to print each
element in the array using a loop like the following:
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 17
Summary
• While Loop
• The do-while Loop
• The for Loop
• Methods
• Arrays
• Summary
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 18
The End
Thank You
Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 19

More Related Content

PPTX
Chapter 5 Loops by z al saeddddddddddddddddddddddddddddddddddd
PDF
Cis 1403 lab5_loops
DOCX
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
PPTX
Java-Programming.forBSITSTUDENTfreespptx
PDF
while- loop understanding with -ease.pdf
PPT
Computer Programming, Loops using Java
PDF
Lecture15 comparisonoftheloopcontrolstructures.ppt
PPTX
Java covers syntax, data types, object-oriented concepts, control flow, excep...
Chapter 5 Loops by z al saeddddddddddddddddddddddddddddddddddd
Cis 1403 lab5_loops
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
Java-Programming.forBSITSTUDENTfreespptx
while- loop understanding with -ease.pdf
Computer Programming, Loops using Java
Lecture15 comparisonoftheloopcontrolstructures.ppt
Java covers syntax, data types, object-oriented concepts, control flow, excep...

Similar to Advanced Java - Lec #2 ~ Practical Work Examples.pptx (20)

PDF
Loops and Files
PPT
Cso gaddis java_chapter4
PPTX
130707833146508191
PPT
C++ CH3-P2 using c++ in all other parts.ppt
PDF
Chapter 00 revision
PPT
Java Programming: Loops
PPT
Eo gaddis java_chapter_05_5e
PPT
Eo gaddis java_chapter_05_5e
PDF
DSA 103 Object Oriented Programming :: Week 3
PDF
Chapter_05HGUYUYGUYGUTFTIVVGUTFGIHGHYIYUIGY
PPTX
PDF
Week04
PPTX
Final requirement for programming-Bonifacio, Mary Clemence
PPT
Iteration
PDF
Week 1
PPTX
Pi j1.4 loops
PPTX
Loop And For Loop in C++ language .pptx
PPT
Comp102 lec 6
PPT
12 lec 12 loop
PPT
06 Loops
Loops and Files
Cso gaddis java_chapter4
130707833146508191
C++ CH3-P2 using c++ in all other parts.ppt
Chapter 00 revision
Java Programming: Loops
Eo gaddis java_chapter_05_5e
Eo gaddis java_chapter_05_5e
DSA 103 Object Oriented Programming :: Week 3
Chapter_05HGUYUYGUYGUTFTIVVGUTFGIHGHYIYUIGY
Week04
Final requirement for programming-Bonifacio, Mary Clemence
Iteration
Week 1
Pi j1.4 loops
Loop And For Loop in C++ language .pptx
Comp102 lec 6
12 lec 12 loop
06 Loops
Ad

Recently uploaded (20)

PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
history of c programming in notes for students .pptx
PDF
Cost to Outsource Software Development in 2025
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
medical staffing services at VALiNTRY
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Patient Appointment Booking in Odoo with online payment
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Complete Guide to Website Development in Malaysia for SMEs
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
AutoCAD Professional Crack 2025 With License Key
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
assetexplorer- product-overview - presentation
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
history of c programming in notes for students .pptx
Cost to Outsource Software Development in 2025
CHAPTER 2 - PM Management and IT Context
medical staffing services at VALiNTRY
Wondershare Filmora 15 Crack With Activation Key [2025
Computer Software and OS of computer science of grade 11.pptx
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
Advanced SystemCare Ultimate Crack + Portable (2025)
Designing Intelligence for the Shop Floor.pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Patient Appointment Booking in Odoo with online payment
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Complete Guide to Website Development in Malaysia for SMEs
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
AutoCAD Professional Crack 2025 With License Key
Operating system designcfffgfgggggggvggggggggg
assetexplorer- product-overview - presentation
Ad

Advanced Java - Lec #2 ~ Practical Work Examples.pptx

  • 1. 1 In the name of Allah Ghalib University Computer Science Faculty General Department Advanced Java Lecture Title Lecture #2 Practical Work Examples Subject: Advanced Java Instructor: Mohammad Dawood Saddiqi Date: Saturday, July 5, 2025
  • 2. List of Contents • At First Some Questions • While Loop • The do-while Loop • The for Loop • Methods • Arrays • Summary Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 2
  • 3. At First Some Questions • What is Loop? • What is Loop body? • What is iteration of a Loop? • Can you convert a for loop to a while loop? • What is Method? • What is Array? Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 3
  • 4. While Loop Example #1 • We want to develop a program that prompts the user to enter an answer for a question on addition of two single digits. Using a loop, you can rewrite the program to let the user repeatedly enter a new answer until it is correct. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 4
  • 5. Cont. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 5
  • 6. Cont. Example #2 • The problem is to guess what number a computer has in mind. You will write a program that randomly generates an integer between 0 and 100, inclusive. The program prompts the user to enter a number continuously until the number matches the randomly generated number. For each user input, the program tells the user whether the input is too low or too high, so the user can make the next guess intelligently. Here is a sample run: Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 6
  • 7. Cont. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 7
  • 8. The do-while Loop Example #3 • Suppose the input is 2 3 4 5 0. What is the output of the following code? Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 8
  • 9. The for Loop Example #4 • Suppose the input is 2 3 4 5 0. What is the output of the following code? Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 9
  • 10. Cont. Example #5 • Write a program that uses nested for loops to display a multiplication table. • Like this: Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 10
  • 11. Cont. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 11 The Answer:
  • 12. Methods Example #6 • Redesign the printGrade method to return a value. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 12
  • 13. Cont. • The answer: Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 13
  • 14. Cont. Example #7 • Identify and correct the errors in the following program: Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 14
  • 15. Arrays Example #8 • Initializing arrays with input values: The following loop initializes the array myList with user input values. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 15
  • 16. Cont. Example #9 • Initializing arrays with random values: The following loop initializes the array myList with random values between 0.0 and 100.0, but less than 100.0. Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 16
  • 17. Cont. Example #10 • Displaying arrays: To print an array, you have to print each element in the array using a loop like the following: Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 17
  • 18. Summary • While Loop • The do-while Loop • The for Loop • Methods • Arrays • Summary Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 18
  • 19. The End Thank You Saturday, July 5, 2025 Instructor: Saddiqi- Ghalib University 19