computational expression
play

Computational Expression Arrays, Do While Loop, For Loop Janyl - PowerPoint PPT Presentation

Computational Expression Arrays, Do While Loop, For Loop Janyl Jumadinova 18-20 November, 2019 Janyl Jumadinova Computational Expression 18-20 November, 2019 1 / 17 Review: ArrayList class To use the methods of ArrayList , we need to create


  1. Computational Expression Arrays, Do While Loop, For Loop Janyl Jumadinova 18-20 November, 2019 Janyl Jumadinova Computational Expression 18-20 November, 2019 1 / 17

  2. Review: ArrayList class To use the methods of ArrayList , we need to create an instance of an ArrayList . ArrayList has methods that allow us to add, remove, change elements in the list. ArrayList supports dynamic arrays that can grow as needed. Janyl Jumadinova Computational Expression 18-20 November, 2019 2 / 17

  3. Review: ArrayList class To use the methods of ArrayList , we need to create an instance of an ArrayList . ArrayList has methods that allow us to add, remove, change elements in the list. ArrayList supports dynamic arrays that can grow as needed. Iterator Can use an Iterator class’s hasNext() and next() methods to process ArrayList Janyl Jumadinova Computational Expression 18-20 November, 2019 2 / 17

  4. Standard Java arrays An array is a logical, homogenous collection of data elements, grouped together under a common variable name and referenced individually by position number. Janyl Jumadinova Computational Expression 18-20 November, 2019 3 / 17

  5. Standard Java arrays An array is a logical, homogenous collection of data elements, grouped together under a common variable name and referenced individually by position number. An array in Java is a reference type since it is an object. Janyl Jumadinova Computational Expression 18-20 November, 2019 3 / 17

  6. Standard Java arrays An array is a logical, homogenous collection of data elements, grouped together under a common variable name and referenced individually by position number. An array in Java is a reference type since it is an object. To refer to a particular location or element in the array, we specify the name of the array and the position number of the particular element in the array. Janyl Jumadinova Computational Expression 18-20 November, 2019 3 / 17

  7. Declaring Arrays Arrays occupy a fixed amount of space in memory. The programmer specifies the type of each element and the number of elements required by each array so that the compiler may reserve the appropriate amount of space in memory for the array. Janyl Jumadinova Computational Expression 18-20 November, 2019 4 / 17

  8. Arrays Janyl Jumadinova Computational Expression 18-20 November, 2019 5 / 17

  9. Arrays Janyl Jumadinova Computational Expression 18-20 November, 2019 6 / 17

  10. Arrays Janyl Jumadinova Computational Expression 18-20 November, 2019 7 / 17

  11. Arrays Janyl Jumadinova Computational Expression 18-20 November, 2019 8 / 17

  12. Arrays Janyl Jumadinova Computational Expression 18-20 November, 2019 9 / 17

  13. Declaring Arrays Arrays can be initialized using a comma-separated initializer list. int [] n = { 32, 27, 64, 19, 95, 14, 90, 70, 37 } . Janyl Jumadinova Computational Expression 18-20 November, 2019 10 / 17

  14. Declaring Arrays Arrays can be initialized using a comma-separated initializer list. int [] n = { 32, 27, 64, 19, 95, 14, 90, 70, 37 } . The size of the array is inferred from the number of elements in the initializer list. Janyl Jumadinova Computational Expression 18-20 November, 2019 10 / 17

  15. Processing Arrays To iterate through an array, we use a loop. To get the number of elements (size) in the array: arrayName.length; int i = 0; int [] n = new int [10]; while(i < n.length) { n = i*10; i++; } Janyl Jumadinova Computational Expression 18-20 November, 2019 11 / 17

  16. Review: Repetition structures while() loop while (condition) { action(s) } Janyl Jumadinova Computational Expression 18-20 November, 2019 12 / 17

  17. Review: Repetition structures while() loop while (condition) { action(s) } Janyl Jumadinova Computational Expression 18-20 November, 2019 13 / 17

  18. Review: Repetition structures while() loop while (condition) { action(s) } - Example: int num = 10; while(num < 10) { System.out.print(num + " "); num++; } Janyl Jumadinova Computational Expression 18-20 November, 2019 13 / 17

  19. Review: Repetition structures while() loop while (condition) { action(s) } - Example: int num = 10; while(num < 10) { System.out.print(num + " "); num++; } Output : Janyl Jumadinova Computational Expression 18-20 November, 2019 13 / 17

  20. Repetition structures do { } while() loop do { action(s) } while(condition); Janyl Jumadinova Computational Expression 18-20 November, 2019 14 / 17

  21. Repetition structures do { } while() loop do { action(s) } while(condition); Janyl Jumadinova Computational Expression 18-20 November, 2019 15 / 17

  22. Repetition structures do { } while() loop do { action(s) } while(condition); - Example: int num = 10; do { System.out.print(num + " "); num++; } while(num < 10); Janyl Jumadinova Computational Expression 18-20 November, 2019 15 / 17

  23. Repetition structures do { } while() loop do { action(s) } while(condition); - Example: int num = 10; do { System.out.print(num + " "); num++; } while(num < 10); Output : 10 Janyl Jumadinova Computational Expression 18-20 November, 2019 15 / 17

  24. For repetition structure for ( init; testForFinal; modification ) { actionStatement(s); } The init section should create and initialize your loop control variable. The testForFinal section should be a Boolean expression to test for the final value. The modification section should be an arithmetic statement (usually increment ++ or decrement - - action) to modify the loop control variable. Janyl Jumadinova Computational Expression 18-20 November, 2019 16 / 17

  25. For loop public class ForLoop { public static void main ( String args[] ) { for ( int counter = 1; counter <= 10; counter++) System.out.println ( counter ); } } Janyl Jumadinova Computational Expression 18-20 November, 2019 17 / 17

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend