We are launching ICA Placement Programs in JAVA, which will be used for students and freshers. This initiative is very useful for all, you will learn the JAVA program and syntax parallelly, and we are teaching some specific programs and their functionality from scratch.

  1. Introduction about Array
    • Array Initialization

Software and Tools:

We have used Notepad++ software for running the JAVA program in the computer before running the program you will install JDK (Java SE Development Kit 20.0.1) in your computer.

Software:

Notepad++ v8.5.3

Install JDK (JAVA SE Development Kit 20.0.1)

Verify your system: (use the below-mentioned command)

1. Open Command prompt or Windows + R

2. Then enter the command cmd

3. After opening the command prompt use this command (java –version)

4. Then it will show whether any JDK file exists or not, if no files are there you will install JDK in your computer.

1.  Introduction to the array

In computer science, an array is a data structure that stores a collection of elements such as values or variables, all elements are stored in an array format of the same data type, and the values are stored in the array in the index format, index value starting from 0 to n values,  for example, the array size is 5 the index value is start from 0 and end with 4 (0,1,2,3,4) the value the size of an array is typically fixed at the time of creation, although some programming languages allow dynamic resizing of arrays during runtime.

Diagrammatic example:

The array size is 5, and the values are 10,20,30,40,50.

1020304050
Index Value ->01234

1.1 Array Initialization

To initialize an array in Java with user input, you can use the Scanner class from the java.util package. The Scanner class is used to get the input from the user. Here’s an example of how you can initialize an array with user input in Java:

I have upload video in YouTube for a full demonstration of the array initialization link will be given below

Program in JAVA:

import java.util.Scanner;

public class ArrayInitialization {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the size of the array: ");
        int size = scanner.nextInt();

        int[] array = new int[size];

        System.out.println("Enter the elements of the array:");

        for (int i = 0; i < size; i++) {
            System.out.print("Enter element " + (i + 1) + ": ");
            array[i] = scanner.nextInt();
        }

        System.out.println("Array elements:");
        for (int i = 0; i < size; i++) {
            System.out.println("Element " + (i + 1) + ": " + array[i] + " Index value:"+i);
        }

        scanner.close();
    }
}

Sample Output:

D:\Prabakaran S\Website\ICA_Placement_Programs>javac ArrayInitialization.java

D:\Prabakaran S\Website\ICA_Placement_Programs>java ArrayInitialization

Enter the size of the array: 5

Enter the elements of the array:

Enter element 1: 10

Enter element 2: 20

Enter element 3: 30

Enter element 4: 40

Enter element 5: 50

Array elements:

Element 1: 10 Index value:0

Element 2: 20 Index value:1

Element 3: 30 Index value:2

Element 4: 40 Index value:3

Element 5: 50 Index value:4

Leave a Reply

Your email address will not be published. Required fields are marked *