Sunteți pe pagina 1din 2

1. What is an array?

In computer science an array[1] is a data structure consisting of a group


of elements that are accessed by indexing. In most programming
languages each element has the same data type and the array
occupies a contiguous area of storage.

2. Wahat is a 2 demensional array?

• A two-dimensional array is an array in with both rows and


columns. In contrast, gave one dimensional array is simply a
linear sequence of elements.
• When we define or use a two-dimensional array, we must
supply both the row and column numbers. Two-dimensional
arrays are good for modeling flat surfaces, for example, the
screen of a computer, the layout of a warehouse, or a map.
Capital flat surface has two dimensions, and so a two-
dimensional array can easily model it.
• Java has the ability to define and use arrays with dimensions
higher than 2. For example, you can define an array with
three dimensions to model physical space, or for dimensions
to model physical space with a time dimension. Higher
dimensional arrays are common in some applications, such as
engineering and physics. However, most applications that use
arrays only need one or two-dimensional arrays.

3. why are arrays easier to use than a bunch of related variables?

4. import java.io.*;

class one_Int_array{

public static void main(String args[]) throws


IOException{

BufferedReader stdin = new BufferedReader(new


InputStreamReader(System.in));

String str;

int marks[ ] = new int[6];


int sum;

//Accepting the marks

for(int i=0; i<5; i++){

System.out.print("Enter mark" +(i+1)+":");

str = stdin.readLine();

marks[i] = Integer.parseInt(str);

//Displaying the array

for(int i=0; i<5; i++){

System.out.println("Marks" +(i+1)+ ":"


+marks[i]);

System.out.println("=================");

sum = marks[0] + marks[1] + marks[2] +


marks[3] + marks[4];

System.out.println("Sum Of All Marks :" +


sum);

S-ar putea să vă placă și