SlideShare a Scribd company logo
Programming in Java
Lecture 10: Arrays
Array
• Definition:
An array is a group/collection of variables of the
same type that are referred to by a common name.
• Arrays of any type can be created and may have one
or more dimensions.
• A specific element in an array is accessed by its index
(subscript).
• Examples:
• Collection of numbers
• Collection of names
• Collection of suffixes
Array of numbers:
Array of names:
Array of suffixes:
Examples
10 23 863 8 229
ment tion ness ves
Sam Shanu Riya
One-Dimensional Arrays
• A one-dimensional array is a list of variables of same
type.
• The general form of a one-dimensional array
declaration is:
type var-name[ ]; array-var = new type[size];
or, type var-name[ ] = new type[size];
Example:
int num [] = new int [10];
Declaration of array variable:
data-type variable-name[];
eg. int marks[];
This will declare an array named ‘marks’ of type ‘int’. But no memory is
allocated to the array.
Allocation of memory:
variable-name = new data-type[size];
eg. marks = new int[5];
This will allocate memory of 5 integers to the array ‘marks’ and it can store
upto 5 integers in it. ‘new’ is a special operator that allocates memory.
Syntax
Accessing elements in the array:
• Specific element in the array is accessed by specifying
name of the array followed the index of the element.
• All array indexes in Java start at zero.
variable-name[index] = value;
Example:
marks[0] = 10;
This will assign the value 10 to the 1st
element in the array.
marks[2] = 863;;
This will assign the value 863 to the 3rd
element in the array.
STEP 1 : (Declaration)
int marks[];
marks  null
STEP 2: (Memory Allocation)
marks = new int[5];
marks 
marks[0] marks[1] marks[2] marks[3] marks[4]
STEP 3: (Accessing Elements)
marks[0] = 10;
marks 
marks[0] marks[1] marks[2] marks[3] marks[4]
Example
0 0 0 0 0
10 0 0 0 0
• Size of an array can’t be changed after the array is created.
• Default values:
– zero (0) for numeric data types,
– u0000 for chars and
– false for boolean types
• Length of an array can be obtained as:
array_ref_var.length
Example
class Demo_Array
{
public static void main(String args[])
{
int marks[];
marks = new int[3];
marks[0] = 10;
marks[1] = 35;
marks[2] = 84;
System.out.println(“Marks of 2nd
student=” + marks[1]);
}
}
• Arrays can store elements of the same data type. Hence an
int array CAN NOT store an element which is not an int.
• Though an element of a compatible type can be converted
to int and stored into the int array.
eg. marks[2] = (int) 22.5;
This will convert ‘22.5’ into the int part ‘22’ and store it into the 3rd
place
in the int array ‘marks’.
• Array indexes start from zero. Hence ‘marks[index]’ refers
to the (index+1)th
element in the array and ‘marks[size-1]’
refers to last element in the array.
Note
Array Initialization
1. data Type [] array_ref_var = {value0, value1, …, value n};
2. data Type [] array_ref_var;
array_ref_var = {value0, value1, …,value n};
3. data Type [] array_ref_var = new data Type [n+1];
array_ref_var [0] = value 0;
array_ref_var [1] = value 1;
…
array_ref_var [n] = value n;
Multi-Dimensional Array
• Multidimensional arrays are arrays of arrays.
• Two-Dimensional arrays are used to represent a table or a
matrix.
• Creating Two-Dimensional Array:
int twoD[][] = new int[4][5];
Conceptual View of 2-Dimensional Array
class TwoDimArr
{
public static void main(String args[])
{
int twoD[][]= new int[4][5];
int i, j, k = 0;
for(i=0; i<4; i++)
for(j=0; j<5; j++)
{
twoD[i][j] = k;
k++;
}
for(i=0; i<4; i++)
{
for(j=0; j<5; j++)
System.out.print(twoD[i][j] + " ");
System.out.println();
}
}
}
• When we allocate memory for a multidimensional
array, we need to only specify the memory for the
first (leftmost) dimension.
int twoD[][] = new int[4][];
• The other dimensions can be assigned manually.
// Manually allocate differing size second dimensions.
class TwoDAgain {
public static void main(String args[]) {
int twoD[][] = new int[4][];
twoD[0] = new int[1];
twoD[1] = new int[2];
twoD[2] = new int[3];
twoD[3] = new int[4];
int i, j, k = 0;
for(i=0; i<4; i++)
for(j=0; j<i+1; j++)
{
twoD[i][j] = k;
k++;
}
for(i=0; i<4; i++) {
for(j=0; j<i+1; j++)
System.out.print(twoD[i][j] + " ");
System.out.println();
}
}
}
Initializing Multi-Dimensional Array
class Matrix {
public static void main(String args[]) {
double m[][] = {
{ 0*0, 1*0, 2*0, 3*0 },
{ 0*1, 1*1, 2*1, 3*1 },
{ 0*2, 1*2, 2*2, 3*2 },
{ 0*3, 1*3, 2*3, 3*3 }
};
int i, j;
for(i=0; i<4; i++) {
for(j=0; j<4; j++)
System.out.print(m[i][j] + " ");
System.out.println();
}
}
}
Alternative Array Declaration
type[ ] var-name;
• Example:
char twod1[][] = new char[3][4];
char[][] twod2 = new char[3][4];
• This alternative declaration form offers convenience
when declaring several arrays at the same time.
• Example: int[] nums, nums2, nums3;
Array Cloning
• To actually create another array with its own values,
Java provides the clone()method.
• arr2 = arr1; (assignment)
is not equivalent to
arr2 = arr1.clone(); (cloning)
Example: ArrayCloning.java
Array as Argument
• Arrays can be passed as an argument to any method.
Example:
void show ( int []x) {}
public static void main(String arr[]) {}
void compareArray(int [] a, int [] b ){}
Array as a return Type
• Arrays can also be returned as the return type of any
method
Example:
public int [] Result (int roll_No, int marks )
Assignment for Practice
• WAP in which use a method to convert all the double
values of argumented array into int.
public int[] double_To_Int(double [] ar)
• WAP to create a jagged Array in which rows and
columns should be taken as input from user.
L10 array

More Related Content

What's hot (20)

PPTX
Introduction to Array ppt
sandhya yadav
 
PDF
Lecture17 arrays.ppt
eShikshak
 
PPTX
Array in c#
Prem Kumar Badri
 
PPTX
Arrays in c
Jeeva Nanthini
 
PPT
Core java day2
Soham Sengupta
 
PPTX
Array in C
Kamal Acharya
 
PPTX
Row major and column major in 2 d
nikhilarora2211
 
PPT
Arrays
Manthan Dhavne
 
PPT
Chap09
Terry Yoast
 
PPTX
Array in Java
Ali shah
 
PPTX
A Presentation About Array Manipulation(Insertion & Deletion in an array)
Imdadul Himu
 
PPT
Mesics lecture 8 arrays in 'c'
eShikshak
 
PPSX
C Programming : Arrays
Gagan Deep
 
PPT
Algo>Arrays
Ain-ul-Moiz Khawaja
 
PPT
Arrays Basics
Nikhil Pandit
 
PPTX
Multi-Dimensional Lists
primeteacher32
 
PPTX
Arrays in java (signle dimensional array)
Talha mahmood
 
PDF
Arrays
Learn By Watch
 
PPTX
Arrays
Mubashar Iqbal
 
PPTX
Array in c
AnIsh Kumar
 
Introduction to Array ppt
sandhya yadav
 
Lecture17 arrays.ppt
eShikshak
 
Array in c#
Prem Kumar Badri
 
Arrays in c
Jeeva Nanthini
 
Core java day2
Soham Sengupta
 
Array in C
Kamal Acharya
 
Row major and column major in 2 d
nikhilarora2211
 
Chap09
Terry Yoast
 
Array in Java
Ali shah
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
Imdadul Himu
 
Mesics lecture 8 arrays in 'c'
eShikshak
 
C Programming : Arrays
Gagan Deep
 
Algo>Arrays
Ain-ul-Moiz Khawaja
 
Arrays Basics
Nikhil Pandit
 
Multi-Dimensional Lists
primeteacher32
 
Arrays in java (signle dimensional array)
Talha mahmood
 
Array in c
AnIsh Kumar
 

Similar to L10 array (20)

PPTX
6_Array.pptx
shafat6712
 
PDF
Array
Ravi_Kant_Sahu
 
PPSX
dizital pods session 6-arrays.ppsx
VijayKumarLokanadam
 
PPTX
dizital pods session 6-arrays.pptx
VijayKumarLokanadam
 
PPTX
Java arrays
BHUVIJAYAVELU
 
PPT
Comp102 lec 8
Fraz Bakhsh
 
PDF
Java arrays
Kuppusamy P
 
PPTX
OOPs with java
AAKANKSHA JAIN
 
PPT
Multi dimensional arrays
Aseelhalees
 
PDF
Java chapter 6 - Arrays -syntax and use
Mukesh Tekwani
 
PPTX
javaArrays.pptx
AshishNayyar11
 
PDF
Learn Java Part 9
Gurpreet singh
 
PPTX
How to create a two-dimensional array in java
Kavitha S
 
PPT
Data Structure Midterm Lesson Arrays
Maulen Bale
 
PDF
Arrays a detailed explanation and presentation
riazahamed37
 
PPTX
JAVA WORKSHOP(DAY 3) 1234567889999999.pptx
aniketraj4440
 
PPTX
Chapter6 (4) (1).pptx plog fix down more
mohammadalali41
 
PPT
17-Arrays en java presentación documento
DiegoGamboaSafla
 
PPTX
Arrays in Java with example and types of array.pptx
ashwinibhosale27
 
PPTX
Arrays and Strings engineering education
csangani1
 
6_Array.pptx
shafat6712
 
dizital pods session 6-arrays.ppsx
VijayKumarLokanadam
 
dizital pods session 6-arrays.pptx
VijayKumarLokanadam
 
Java arrays
BHUVIJAYAVELU
 
Comp102 lec 8
Fraz Bakhsh
 
Java arrays
Kuppusamy P
 
OOPs with java
AAKANKSHA JAIN
 
Multi dimensional arrays
Aseelhalees
 
Java chapter 6 - Arrays -syntax and use
Mukesh Tekwani
 
javaArrays.pptx
AshishNayyar11
 
Learn Java Part 9
Gurpreet singh
 
How to create a two-dimensional array in java
Kavitha S
 
Data Structure Midterm Lesson Arrays
Maulen Bale
 
Arrays a detailed explanation and presentation
riazahamed37
 
JAVA WORKSHOP(DAY 3) 1234567889999999.pptx
aniketraj4440
 
Chapter6 (4) (1).pptx plog fix down more
mohammadalali41
 
17-Arrays en java presentación documento
DiegoGamboaSafla
 
Arrays in Java with example and types of array.pptx
ashwinibhosale27
 
Arrays and Strings engineering education
csangani1
 
Ad

More from teach4uin (20)

PPTX
Controls
teach4uin
 
PPT
validation
teach4uin
 
PPT
validation
teach4uin
 
PPT
Master pages
teach4uin
 
PPTX
.Net framework
teach4uin
 
PPT
Scripting languages
teach4uin
 
PPTX
Css1
teach4uin
 
PPTX
Code model
teach4uin
 
PPT
Asp db
teach4uin
 
PPTX
State management
teach4uin
 
PPT
security configuration
teach4uin
 
PPT
static dynamic html tags
teach4uin
 
PPT
static dynamic html tags
teach4uin
 
PPTX
New microsoft office power point presentation
teach4uin
 
PPT
.Net overview
teach4uin
 
PPT
Stdlib functions lesson
teach4uin
 
PPT
enums
teach4uin
 
PPT
memory
teach4uin
 
PPT
array
teach4uin
 
PPT
storage clas
teach4uin
 
Controls
teach4uin
 
validation
teach4uin
 
validation
teach4uin
 
Master pages
teach4uin
 
.Net framework
teach4uin
 
Scripting languages
teach4uin
 
Css1
teach4uin
 
Code model
teach4uin
 
Asp db
teach4uin
 
State management
teach4uin
 
security configuration
teach4uin
 
static dynamic html tags
teach4uin
 
static dynamic html tags
teach4uin
 
New microsoft office power point presentation
teach4uin
 
.Net overview
teach4uin
 
Stdlib functions lesson
teach4uin
 
enums
teach4uin
 
memory
teach4uin
 
array
teach4uin
 
storage clas
teach4uin
 
Ad

Recently uploaded (20)

PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Complete Network Protection with Real-Time Security
L4RGINDIA
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Complete Network Protection with Real-Time Security
L4RGINDIA
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 

L10 array

  • 2. Array • Definition: An array is a group/collection of variables of the same type that are referred to by a common name. • Arrays of any type can be created and may have one or more dimensions. • A specific element in an array is accessed by its index (subscript). • Examples: • Collection of numbers • Collection of names • Collection of suffixes
  • 3. Array of numbers: Array of names: Array of suffixes: Examples 10 23 863 8 229 ment tion ness ves Sam Shanu Riya
  • 4. One-Dimensional Arrays • A one-dimensional array is a list of variables of same type. • The general form of a one-dimensional array declaration is: type var-name[ ]; array-var = new type[size]; or, type var-name[ ] = new type[size]; Example: int num [] = new int [10];
  • 5. Declaration of array variable: data-type variable-name[]; eg. int marks[]; This will declare an array named ‘marks’ of type ‘int’. But no memory is allocated to the array. Allocation of memory: variable-name = new data-type[size]; eg. marks = new int[5]; This will allocate memory of 5 integers to the array ‘marks’ and it can store upto 5 integers in it. ‘new’ is a special operator that allocates memory. Syntax
  • 6. Accessing elements in the array: • Specific element in the array is accessed by specifying name of the array followed the index of the element. • All array indexes in Java start at zero. variable-name[index] = value; Example: marks[0] = 10; This will assign the value 10 to the 1st element in the array. marks[2] = 863;; This will assign the value 863 to the 3rd element in the array.
  • 7. STEP 1 : (Declaration) int marks[]; marks  null STEP 2: (Memory Allocation) marks = new int[5]; marks  marks[0] marks[1] marks[2] marks[3] marks[4] STEP 3: (Accessing Elements) marks[0] = 10; marks  marks[0] marks[1] marks[2] marks[3] marks[4] Example 0 0 0 0 0 10 0 0 0 0
  • 8. • Size of an array can’t be changed after the array is created. • Default values: – zero (0) for numeric data types, – u0000 for chars and – false for boolean types • Length of an array can be obtained as: array_ref_var.length
  • 9. Example class Demo_Array { public static void main(String args[]) { int marks[]; marks = new int[3]; marks[0] = 10; marks[1] = 35; marks[2] = 84; System.out.println(“Marks of 2nd student=” + marks[1]); } }
  • 10. • Arrays can store elements of the same data type. Hence an int array CAN NOT store an element which is not an int. • Though an element of a compatible type can be converted to int and stored into the int array. eg. marks[2] = (int) 22.5; This will convert ‘22.5’ into the int part ‘22’ and store it into the 3rd place in the int array ‘marks’. • Array indexes start from zero. Hence ‘marks[index]’ refers to the (index+1)th element in the array and ‘marks[size-1]’ refers to last element in the array. Note
  • 11. Array Initialization 1. data Type [] array_ref_var = {value0, value1, …, value n}; 2. data Type [] array_ref_var; array_ref_var = {value0, value1, …,value n}; 3. data Type [] array_ref_var = new data Type [n+1]; array_ref_var [0] = value 0; array_ref_var [1] = value 1; … array_ref_var [n] = value n;
  • 12. Multi-Dimensional Array • Multidimensional arrays are arrays of arrays. • Two-Dimensional arrays are used to represent a table or a matrix. • Creating Two-Dimensional Array: int twoD[][] = new int[4][5];
  • 13. Conceptual View of 2-Dimensional Array
  • 14. class TwoDimArr { public static void main(String args[]) { int twoD[][]= new int[4][5]; int i, j, k = 0; for(i=0; i<4; i++) for(j=0; j<5; j++) { twoD[i][j] = k; k++; } for(i=0; i<4; i++) { for(j=0; j<5; j++) System.out.print(twoD[i][j] + " "); System.out.println(); } } }
  • 15. • When we allocate memory for a multidimensional array, we need to only specify the memory for the first (leftmost) dimension. int twoD[][] = new int[4][]; • The other dimensions can be assigned manually.
  • 16. // Manually allocate differing size second dimensions. class TwoDAgain { public static void main(String args[]) { int twoD[][] = new int[4][]; twoD[0] = new int[1]; twoD[1] = new int[2]; twoD[2] = new int[3]; twoD[3] = new int[4]; int i, j, k = 0; for(i=0; i<4; i++) for(j=0; j<i+1; j++) { twoD[i][j] = k; k++; } for(i=0; i<4; i++) { for(j=0; j<i+1; j++) System.out.print(twoD[i][j] + " "); System.out.println(); } } }
  • 17. Initializing Multi-Dimensional Array class Matrix { public static void main(String args[]) { double m[][] = { { 0*0, 1*0, 2*0, 3*0 }, { 0*1, 1*1, 2*1, 3*1 }, { 0*2, 1*2, 2*2, 3*2 }, { 0*3, 1*3, 2*3, 3*3 } }; int i, j; for(i=0; i<4; i++) { for(j=0; j<4; j++) System.out.print(m[i][j] + " "); System.out.println(); } } }
  • 18. Alternative Array Declaration type[ ] var-name; • Example: char twod1[][] = new char[3][4]; char[][] twod2 = new char[3][4]; • This alternative declaration form offers convenience when declaring several arrays at the same time. • Example: int[] nums, nums2, nums3;
  • 19. Array Cloning • To actually create another array with its own values, Java provides the clone()method. • arr2 = arr1; (assignment) is not equivalent to arr2 = arr1.clone(); (cloning) Example: ArrayCloning.java
  • 20. Array as Argument • Arrays can be passed as an argument to any method. Example: void show ( int []x) {} public static void main(String arr[]) {} void compareArray(int [] a, int [] b ){}
  • 21. Array as a return Type • Arrays can also be returned as the return type of any method Example: public int [] Result (int roll_No, int marks )
  • 22. Assignment for Practice • WAP in which use a method to convert all the double values of argumented array into int. public int[] double_To_Int(double [] ar) • WAP to create a jagged Array in which rows and columns should be taken as input from user.

Editor's Notes

  • #13: int i = 7; int j = 2; int k = 4; v[0] = 1; // element 0 of v given value 1 v[i] = 5; // element i of v given value 5 v[j] = v[i] + 3; // element j of v given value // of element i of v plus 3 v[j+1] = v[i] + v[0]; // element j+1 of v given value // of element i of v plus // value of element 0 of v v[v[j]] = 12; // element v[j] of v given // value 12 System.out.println(v[2]); // element 2 of v is displayed v[k] = Integer.parseInt(stdin.readLine()); // element k of v given next // extracted value
  • #14: int i = 7; int j = 2; int k = 4; v[0] = 1; // element 0 of v given value 1 v[i] = 5; // element i of v given value 5 v[j] = v[i] + 3; // element j of v given value // of element i of v plus 3 v[j+1] = v[i] + v[0]; // element j+1 of v given value // of element i of v plus // value of element 0 of v v[v[j]] = 12; // element v[j] of v given // value 12 System.out.println(v[2]); // element 2 of v is displayed v[k] = Integer.parseInt(stdin.readLine()); // element k of v given next // extracted value
  • #15: int i = 7; int j = 2; int k = 4; v[0] = 1; // element 0 of v given value 1 v[i] = 5; // element i of v given value 5 v[j] = v[i] + 3; // element j of v given value // of element i of v plus 3 v[j+1] = v[i] + v[0]; // element j+1 of v given value // of element i of v plus // value of element 0 of v v[v[j]] = 12; // element v[j] of v given // value 12 System.out.println(v[2]); // element 2 of v is displayed v[k] = Integer.parseInt(stdin.readLine()); // element k of v given next // extracted value
  • #16: int i = 7; int j = 2; int k = 4; v[0] = 1; // element 0 of v given value 1 v[i] = 5; // element i of v given value 5 v[j] = v[i] + 3; // element j of v given value // of element i of v plus 3 v[j+1] = v[i] + v[0]; // element j+1 of v given value // of element i of v plus // value of element 0 of v v[v[j]] = 12; // element v[j] of v given // value 12 System.out.println(v[2]); // element 2 of v is displayed v[k] = Integer.parseInt(stdin.readLine()); // element k of v given next // extracted value
  • #17: int i = 7; int j = 2; int k = 4; v[0] = 1; // element 0 of v given value 1 v[i] = 5; // element i of v given value 5 v[j] = v[i] + 3; // element j of v given value // of element i of v plus 3 v[j+1] = v[i] + v[0]; // element j+1 of v given value // of element i of v plus // value of element 0 of v v[v[j]] = 12; // element v[j] of v given // value 12 System.out.println(v[2]); // element 2 of v is displayed v[k] = Integer.parseInt(stdin.readLine()); // element k of v given next // extracted value
  • #18: int i = 7; int j = 2; int k = 4; v[0] = 1; // element 0 of v given value 1 v[i] = 5; // element i of v given value 5 v[j] = v[i] + 3; // element j of v given value // of element i of v plus 3 v[j+1] = v[i] + v[0]; // element j+1 of v given value // of element i of v plus // value of element 0 of v v[v[j]] = 12; // element v[j] of v given // value 12 System.out.println(v[2]); // element 2 of v is displayed v[k] = Integer.parseInt(stdin.readLine()); // element k of v given next // extracted value
  • #19: int i = 7; int j = 2; int k = 4; v[0] = 1; // element 0 of v given value 1 v[i] = 5; // element i of v given value 5 v[j] = v[i] + 3; // element j of v given value // of element i of v plus 3 v[j+1] = v[i] + v[0]; // element j+1 of v given value // of element i of v plus // value of element 0 of v v[v[j]] = 12; // element v[j] of v given // value 12 System.out.println(v[2]); // element 2 of v is displayed v[k] = Integer.parseInt(stdin.readLine()); // element k of v given next // extracted value
  • #20: int i = 7; int j = 2; int k = 4; v[0] = 1; // element 0 of v given value 1 v[i] = 5; // element i of v given value 5 v[j] = v[i] + 3; // element j of v given value // of element i of v plus 3 v[j+1] = v[i] + v[0]; // element j+1 of v given value // of element i of v plus // value of element 0 of v v[v[j]] = 12; // element v[j] of v given // value 12 System.out.println(v[2]); // element 2 of v is displayed v[k] = Integer.parseInt(stdin.readLine()); // element k of v given next // extracted value