One-Dimensional Array Assignment Help

Assignment Help: >> Elements of Java - One-Dimensional Array

One Dimensional Array

A one dimensional array is, essentially, a list of like typed variables. For create an array, you first have to create an array variable of the desired type. The common form of a one dimensional array declaration is

type var-name [ ];

Here, type declares the base type of the array. A base type determines the data type of each element that comprises the array.  Therefore, the base type for the array determines what type of data the array will contain. For instance, the following declares an array named month days along with the type "array of int".

int month_days [ ] ;

Although this declaration established the real fact that month_days is an array variable, no array actually exists.  Actually,  the  value  of  month  days  is  set  to  null,  that represents an array along with no value. For link month_days along with a real, physical array of integers, you must allocate one using new and assign it to month_days. New is a special operator which allocates memory.

The common form of new as it applies to one-dimensional arrays appears as given below:

array -var =new type [size];

Here is a program which creates an array of the numbr of days in every month.

public static void main ( String args [ ]) {

int month_days [ ] ;

month_days = new int [ 5];

month_days [0] = 31;

month_days [1] = 28;

month_days [2] = 31;

month_days [3] = 30;

month_days [4] = 31;

month_days [5] = 30;

System.out.println("April has"+month_day(3)+"days.");

}

}

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd