IP_Lecture_08_Latex PDF - SLIIT University
Document Details
Uploaded by Deleted User
SLIIT University
2023
Dr.Junius Anjana
Tags
Related
- OOP - JAVA Object-Oriented Programming PDF
- Java Programming: Chapter 3 Using Methods, Classes, and Objects PDF
- Concepts des langages objet - Programmation Orientée Objet - JAVA PDF
- Lecture 2 (Chapter 2) Introduction to Java Programming PDF
- DCIT 201 Programming I - Methods PDF
- Introduction To Object Oriented Programming PDF
Summary
This document is a lecture from SLIIT University, Faculty of Computing. It covers the topics of Java Methods, Predefined Methods, Math Class Methods and String Class Methods, including a set of exercises for students. This was used for semester 1 and year 1 for the IT1120 - Introduction to Programming class.
Full Transcript
Sri Lanka Institute of Information Technology Faculty of Computing IT1120 - Introduction to Programming Dr.Junius Anjana Year 01 and Semester 01 Year 01 and Semester 01 1 / 11 Lecture 8 Java Methods...
Sri Lanka Institute of Information Technology Faculty of Computing IT1120 - Introduction to Programming Dr.Junius Anjana Year 01 and Semester 01 Year 01 and Semester 01 1 / 11 Lecture 8 Java Methods Year 01 and Semester 01 2 / 11 Introduction to Java Methods A method is used to break algorithms into smaller parts A method is also known as a function in programming It allows the modularity in programming Generally, a method is designed to perform one task Benefits of using methods: Ease of Design Code Readability Code Re-usability Code Debugging There are two types of methods: Predefined Methods User Defined Methods Year 01 and Semester 01 3 / 11 Java Predefined Methods Year 01 and Semester 01 4 / 11 Using Math Class Methods in java Year 01 and Semester 01 5 / 11 Using Math class methods in java Year 01 and Semester 01 6 / 11 Exercises Write the value of x after each of the following statements is performed: a x = floor (7.5) b x = abs(-3.6) c x = floor (0.0) d x = ceil (-6.4) e x = pow (5, 2) f x = round (2.7) g x = abs(2.5) Year 01 and Semester 01 7 / 11 Java String Class Methods Year 01 and Semester 01 8 / 11 Using String class methods in java Year 01 and Semester 01 9 / 11 Exercises a Given a string ”Hello, World!”, how can you determine the number of characters in the string using an predefined method? b Given a string ” Hello, World! ”, how can you remove the leading and trailing whitespace using the trim() method? c Given a string ”Hello, World!”, how can you access the character at index 7 (where ‘W’ is located) using the charAt() method? d Given a string ”HELLO, WORLD!”, how can you convert it to lowercase using the toLowerCase() method? Year 01 and Semester 01 10 / 11 Thank You! Year 01 and Semester 01 11 / 11