Lecture Java programming language: Loop Structures and Strings - Ho Dac Hung

Chia sẻ: Trinh _ | Ngày: | Loại File: PDF | Số trang:10

lượt xem
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Loop Structures and Strings has main content such as the while statement, the do-while statemen, infinite loops , the for statement, debugging techniques, the string class, the string class, comparing strings.

Chủ đề:

Nội dung Text: Lecture Java programming language: Loop Structures and Strings - Ho Dac Hung

  1. Loop Structures and Strings Ho Dac Hung 1
  2. The while Statement  The while statement is a loop structure, which executes a set of statements over and over again based on a condition. The while statement takes the form: while (){ } 2
  3. The do-while Statement  The do-while statement is an alternative form of the while statement. In the do-while statement the condition is not evaluated until after the first execution of the loop. The do-while takes the following form: do { } while (); 3
  4. Infinite Loops  The condition of a loop is used to determine when the loop should stop executing. A while continues until its conditon is false. What happens though, if the condition never becomes false? The result is an infinite loop – one which continues forever. 4
  5. The for Statement  The for statement is a loop structure that executes a set of statements a fixed number of times. The for statement takes the form: for (; ; ){ } 5
  6. Debugging Techniques  The source of bugs, which are often logic errors, can be hard to determine withoud tools for debugging an application. Debugging is the process of getting an application work correctly.  A debugger is used to select statements where execution will be suspsned. These statements are called breakpoints. 6
  7. The String class  Java includes the String class in the java.lang package for storing and manipulating strings. The String class is large, with numerous methods for string manipulation. 7
  8. The String class  charAt(int index)  length()  isEmpty()  substring(int start, int end)  substring(int start)  toLowerCase()  toUpperCase()  trim()  replace(String str1, String str2)  … 8
  9. Comparing Strings  Strings are compared when determining equality or alphabetical order. Relational operators are used to compare primitive types. When objects need to be comparedm methods from their class are used. Some of the String class methods are used to compare strings. 9
  10. Comparing Strings  equals(String str)  equalsIgnoreCase(String str)  compareTo(String str)  compareToIgnoreCase(String str)  indexOf(String str)  startWith(String str)  endWith(String str)  … 10



Đồng bộ tài khoản