Java Training in Chennai – Arrays – Learning – Part – I
Here in this blog we are going to discuss about Java Training in Chennai – Arrays – Learning – Part – I . They are illustrated very well below .
________________________________________________________________________________
class Test {
public static void main(String args[]) {
int arr[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}
class Test {
public static void main(String args[]) {
int arr[] = new int[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}
public class Main {
public static void main(String args[]) {
int arr[][] = new int[4][];
arr[0] = new int[1];
arr[1] = new int[2];
arr[2] = new int[3];
arr[3] = new int[4];
int i, j, k = 0;
for (i = 0; i < 4; i++) {
for (j = 0; j < i + 1; j++) {
arr[i][j] = k;
k++;
}
}
for (i = 0; i < 4; i++) {
for (j = 0; j < i + 1; j++) {
System.out.print(” ” + arr[i][j]);
k++;
}
System.out.println();
}
}
}
class Test
{
public static void main (String[] args)
{
int arr1[] = {1, 2, 3};
int arr2[] = {1, 2, 3};
if (arr1 == arr2)
System.out.println(“Same”);
else
System.out.println(“Not same”);
}
}
class Test
{
public static void main (String[] args)
{
int arr1[] = {1, 2, 3};
int arr2[] = {1, 2, 3};
if (Arrays.equals(arr1, arr2))
System.out.println(“Same”);
else
System.out.println(“Not same”);
}
}
class Test
{
public static void main (String[] args)
{
int arr1[] = {1, 2, 3};
int arr2[] = {1, 2, 3};
if (arr1.equals(arr2))
System.out.println(“Same”);
else
System.out.println(“Not same”);
}
}
public static void main(String[] args) {
int[] a = new int[0];
System.out.print(a.length);
}
public class Tester {
static void test(int[] a) {
int[] b = new int[2];
a = b;
System.out.print(b.length);
System.out.print(a.length);
}
public static void main(String[] args) {
int[] a = new int[5];
test(a);
System.out.print(a.length);
}
}
public static void main(String[] args) {
String entries[] = {“entry1″,”entry2”};
int count=0;
while (entries [count++]!=null){
System.out.println(count);
}
System.out.println(count);
}
public class Tester {
final static int x[] = new int[5];
public static void main(String[] args) {
final int x = new Tester().x[5];
if (x <= 10)
System.out.println(“payilagam”);
}
}
public static void main(String[] args)
{
byte b1= 25;
byte b2=45;
byte b3= b1+b2;
}
public class MyProg{
public static void main(String arg[])
{
System.out.println(arg[2]);
}
}
int []a = {1,2,3,4,5,6};
int i = a.length – 1;
while(i>=0){
System.out.print(a[i]);
i–;
}
class Ex1{
public static void main(String[] args) {
int a[] = { 1,2,3,4};
System.out.print(a instanceof Object);
}
}
class Ex1{
public static void main(String[] args) {
int a[] = { 1,2,053,4};
int b[][] = { {1,2,4} , {2,2,1},{0,43,2}};
System.out.print(a[3]==b[0][2] );
System.out.print(” ” + (a[2]==b[2][1]));
}
class Ex1{
public static void main(String[] args) {
int a[][] = new int[3][];
a[1] = new int[]{1,2,3};
a[2] = new int[]{4,5};
System.out.print(a[1][1]);
}
}
int[] array = { 1, 4, 3, 6, 8, 2, 5};
int what = array[0];
// scan the array
for ( int index=0; index < array.length; index++ )
{
if ( array[ index ] > what )
what = array[ index ];
}
System.out.println( what );
_______________________________________________________________________________
REFERENCES : www.proprofs.com, meritcampus.com, www.geeksforgeeks.org, www.f5java.com,
dzone.com, www.examveda.com, beingzero.in/, scjptest.com, www.gocertify.com,
web.cs.iastate.edu, www.sanfoundry.com, https://codingpuzzles.com