0% found this document useful (0 votes)
5 views17 pages

Java Presentation3 Array Loops

The document outlines a Java course by Eng. Abdelaziz Said, focusing on key concepts such as variables, arrays, and loops in Java. It discusses the advantages and disadvantages of arrays, types of arrays, and provides examples and exercises for single and multidimensional arrays. Additionally, it covers different types of loops and includes assignments for practical application of the concepts learned.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views17 pages

Java Presentation3 Array Loops

The document outlines a Java course by Eng. Abdelaziz Said, focusing on key concepts such as variables, arrays, and loops in Java. It discusses the advantages and disadvantages of arrays, types of arrays, and provides examples and exercises for single and multidimensional arrays. Additionally, it covers different types of loops and includes assignments for practical application of the concepts learned.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Course

BY
ENG. ABDELAZIZ SAID
2

Variables
in Java
3

Array in Java
Important Notes for Arrays 4

 Arrays contain elements of a similar data type.


 Arrays must include contiguous memory locations.
 We can store only a fixed set of elements in a Java array.
 An array in Java is index-based; the first element of the array is
stored at the 0th index, 2nd element is stored at the 1st index, and
so on.
Advantages of Array 5

 Code Optimization: It optimizes the code, and we can retrieve or


sort the data efficiently.
 Random access: We can get any data located at an index position.
 Manipulation: We can easily perform operations on its elements.
Disadvantages of Array 6

 Size Limit: We can store only a fixed number of elements in the array.
It doesn't grow in size at runtime.
Types of Array 7

 Single-Dimensional Array

 Multidimensional Array
Single Dimensional Array 8

1. dataType[] arr; // best practice


2. dataType []arr;
3. dataType arr[];
Instantiation of the Single 9

Dimensional Array
1. arrayRefVar = new datatype[size];
Exercise (1) 10

 Write a Java program to save students’ Java Exam scores in


memory and display them when the number of students reaches
the maximum (10).
MultiDimensional Array 11

1. dataType[][] arrayRefVar; // best practice


2. dataType [][]arrayRefVar;
3. dataType arrayRefVar[][];
4. dataType []arrayRefVar[];
Instantiation of the 12

Multidimensional Array
1. int[][] arr = new int[3][3];

2. arr[0][0]=1;
3. arr[0][1]=2;
4. arr[0][2]=3;
5. arr[1][0]=4;
6. arr[1][1]=5;
7. arr[1][2]=6;
8. arr[2][0]=7;
9. arr[2][1]=8;
10. arr[2][2]=9;
Exercise (2) 13

 Write a Java program to show a matrix with 4*4 (4 rows & 4 columns)
Loops 14

 Java loops are used to iterate over a portion of the program


multiple times.

 There are three types of loops in Java:


 for loop
 while loop
 do-while loop
For Loop 15

 The Java for loop is used several times to iterate over a part of the
program.

 There are four types of for loops in Java:


 Indexed for loop
 Enhanced for
 Nested for loop
 Infinitive for loop
Exercise (2) 16

 Write a Java program to print all even numbers from 0 to 10


 Write a Java Program to draw the following diagram
*
**
***
****
*****
 Write an enhanced for loop to check for every element in an array
with length 5, if the element is greater than or less than 100
Assignment 17

 Write a Java program to print the following form


----------
----------
----------
----------
----------
 Write a Java program to calculate the average of the array
elements values
 Write a Java program to check if the array includes a vowel
character or not

You might also like