सीधे मुख्य सामग्री पर जाएं

#34 How to use Array in Java ? Types of Array | 1D Array & 2D Array Example

package com.sudhirtheindian2.java123;


import java.util.Scanner;

public class array_class {
public static void main(String[] args) {


//

// How to use and print element of an array in java
// What is array ?

// Array is an object in java which contains similar type of data
// in contiguous memory location

// 1 array index starts with 0

// types of array
// 1D array
// 2Darray

// for programmer
// int[] a= {4,5,6,9,3};
//
// for (int c:a){
// System.out.print(c+" ");
// }


// and

// for user
int[] a = new int[5];
System.out.println("enter your array element");
Scanner scanner = new Scanner(System.in);
for(int i =0;i<5;i++){
a[i]= scanner.nextInt();
}
System.out.println("your printed array is : ");
for (int d:a){
System.out.print(d+" ");
}

}
}

टिप्पणियाँ

इस ब्लॉग से लोकप्रिय पोस्ट