LEC: 14 | JAVA
LEC:14
Arrays in JAVA
Source Code:
package lec_5;
import java.util.*;
public class Lec_5 {
public static void main(String[] args) {
int elements[]={22,33,65,7778,54,656,24,77};
//accessing individual elements of array
// System.out.println("the element at position 1 : "+elements[0]);
// System.out.println("the element at position 2 : "+elements[1]);
// System.out.println("the element at position 3 : "+elements[2]);
// System.out.println("the element at position 4 : "+elements[3]);
// System.out.println("the element at position 5 : "+elements[4]);
//printing all the elements of array
//int size_element=elements.length;
// for(int i=0;i<size_element;i++)
// {
// System.out.println("the element at position: " + i +" is : " +elements[i]);
// }
//for each loop for array
//for(type variable: array_name)
//{
// //statements;
//}
//for(int i : elements)
//{
// System.out.println("the element is " +i);
//}
//changing individual elements of array
System.out.println("before changing : "+elements[0]);
elements[0]=577;
System.out.println("After changing : "+elements[0]);
}
}
Comments
Post a Comment