This is a Tutorial site for school and college students. Programs and technical analysis on BlueJ for ICSE and ISC Students, C programming, C++ programming and Data structure through C programming language are posted here. Engineering college students can get help on C and C++ languages from this site. Undergraduate and Postgraduate admission related information is also available in this site.
Search This Blog
Wednesday, July 14, 2010
Two dimensional or 2 d array in BlueJ programs
Two -dimensional array is actually array of arrays. To declare a two-dimensional array variable, specify each additional index using another set of square brackets. For example, to create a two-dimensional integer array named arr, the syntax is:int arr =new int[x][y]; Unlike C Programming Language , Java arrays are dynamic.
This means that an array of size 'x' will be created, while within each index there will be another array of size 'y'.
Consider the following program:-
Marks obtained in three subjects by three students is
Roll no. 1
Roll no. 2
Roll no. 3
If we were asked to store the marks obtained by Roll no.1, then we can simply create an one dimensional array of size 4. Then the Roll no and three subject marks can be stored in the array variable. But here the case is different. We have to store the values in the tabular form in a variable. Here comes the utility of two-dimensional array. We have to declare a 3 by 4 array.
System.out.println ("Enter the marks of subject no “ + j + “:”);
System.out.println ("The stored values are:");
for (i=0;i< 3;i++)
for (j=0;j< 4;j++)
System.out.println (" "+ result [i][j]);
Here is another program on two dimensional array using BlueJ.
The daily maximum temperature of 4 cities for 5 dates are recorded during the month of January. Write a program to find the day and city corresponding to @. highest temperature and @. lowest temperature