Computer Science, asked by preethamv, 6 months ago


WAP that creates an integer
array of 10 elements, accepts
value for array elements from
the user and display the value
is different line
*​

Answers

Answered by ankajvaish2016
1

Answer:

Declaring a Variable to Refer to an Array

This line of code from the sample program declares an array variable:

int[] anArray; // declare an array of integers

Like declarations for variables of other types, an array declaration has two components: the array's type and the array's name. An array's type is written type[], where type is the data type of the elements contained within the array, and [] indicates that this is an array. Remember that all of the elements within an array are of the same type. The sample program uses int[], so the array called anArray will be used to hold integer data. Here are declarations for arrays that hold other types of data:

float[] anArrayOfFloats;

boolean[] anArrayOfBooleans;

Object[] anArrayOfObjects;

String[] anArrayOfStrings;

You can write an array declaration like this:

float anArrayOfFloats[]; //this form is discouraged

However, convention discourages this form because the brackets identify the array type, and so they should appear with the type designation, not with the array name.

As with declarations for variables of other types, the declaration for an array variable does not create an array and does not allocate any memory to contain array elements. The code must create the array explicitly and assign it to anArray.

Explanation:

IF IT HELPS THEN FOLLOW ME

Answered by anindyaadhikari13
5

Question:-

Write a program that creates an integer array of 10 elements, accepts value for areay elements from user and display the value in different lines.

Program:-

Here is your program written in Java.

import java.util.*;

class ArrayExample

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter 10 elements for the array. ");

int a[]=new int[10];

for(int i=0;i<=9;i++)

{

System.out.print("Enter: ");

a[i]=sc.nextInt();

}

for(int i=0;i<10;i++)

System.out.println(a[i]);

}

}

Similar questions