Java Training in Chennai – Arrays – Learning – Part – II

Java Training in Chennai – Arrays – Learning – Part – II

Here in this blog we are going to discuss about Java Training in Chennai – Arrays – Learning – Part – II . They are illustrated very well below .

   We have already discussed about some programs in the previous blog “Java Training in Chennai – Arrays – Learning “

 REFERENCE :   Java Training in Chennai – Arrays – Learning – Part – I

https://payilagam.com/blogs/java-training-in-chennai-arrays-learning/

COURTESY  :       www.proprofs.commeritcampus.com,  www.geeksforgeeks.org www.f5java.com,

                                     dzone.com, www.examveda.combeingzero.in/scjptest.com,  www.gocertify.com,

                                    web.cs.iastate.eduwww.sanfoundry.com, https://codingpuzzles.com

__________________________________________________________________________________

class MultidimensionArray {

        public static void main(String args[])

        {

            int arr[][] = new int[3][];

            arr[0] = new int[1];

            arr[1] = new int[2];

            arr[2] = new int[3];              

                int sum = 0;

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

                    for (int j = 0; j < i + 1; ++j)

                    arr[i][j] = j + 1;

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

                    for (int j = 0; j < i + 1; ++j)

                    sum + = arr[i][j];

                System.out.print(sum);        

        }

    }

 

class Evaluate {

        public static void main(String args[])

            {

                    int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9};

                    int n = 6;

                n = arr[arr[n] / 2];

                    System.out.println(arr[n] / 2);

            }

    }

 

class Array_output {

        public static void main(String args[])

        {

            char array_variable [] = new char[10];

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

                array_variable[i] = ‘i’;

                System.out.print(array_variable[i] + “”);

            }

        }

    }

 

class Array_output {

        public static void main(String args[])

        {

            int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}};

            int sum = 0;

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

                for (int j = 0; j <  3 ; ++j)

                    sum = sum + array_variable[i][j];

            System.out.print(sum / 5);

        }

    }

 

public boolean isUniqueChars2(String str) {

   if (str.length() > 256) return false;

   boolean[] char_set = new boolean[256];

   for (int 1 = 0; i < str.length(); i++) {

      int val = str.charAt(i);

      if (char_set[val]) { // Already found this char in string

         return false;

      }

      char_set[val] = true;

   }

   return true;

}

 

public class RemoveCharacterFromString {

    public static void main (String[] args) {

        System.out.println (removeCharInString

                           (“My name is the Doctor”,  ‘a’));

    }

    public static String removeCharInString

                           (String str, char charToBeRemoved) {

        if (str == null)

            return “”;

        StringBuilder strBuild = new StringBuilder ();

        for (int i = 0; i < str.length (); i++) {

            char ch = str.charAt (i);

            if (ch == charToBeRemoved)

                continue;

            strBuild.append (ch);

        }

        return strBuild.toString();

    }

}

What will be the output of the following program?

public class TopToBottom {

    public static void main(String[] args) {

        char[] c = {‘P’,’A’,’Y’,’I’,’L’,’A ‘,’G’,’A’,’M’};

        TopToBottom.Top(c);

    }

    private static void Top(char[] AssertionError) {

        System.out.println(AssertionError);

    }

}

 

What will be the output of the following program?

public class DemoOnArrays

{

    public static void main(String args[])

    {

        int[] firstInput, secondInput;

        firstInput = new int[2];

        secondInput = 011;

        firstInput[0] = firstInput[1] = secondInput;

        System.out.print(firstInput[0] + firstInput[1]);

    }

}

What will be the output of the following program?

public class College {

    public static void main(String[] args) {

        Student[] student = new Student[1];

        student[0] = new Student();

        student[0].name = “Khan”;

        student[0].marks = 92;

        student[0].section = ‘A’;

        for (Student element : student) {

            System.out.print(element.name + ” ~ “);

            System.out.print(element.marks + ” ~ “);

            System.out.print(element.section);

        }

    }

}

class Student {

    String name;

    int marks;

    char section;

}

What will be the output of the following program?

public class College {

    public static void main(String[] args) {

        Student[] student = new Student[1];

        student[0].name = “Khan”;

        student[0].marks = 92;

        student[0].section = ‘A’;

        for (Student element : student) {

            System.out.print(element.name + ” ~ “);

            System.out.print(element.marks + ” ~ “);

            System.out.print(element.section);

        }

    }

}

class Student {

    String name;

    int marks;

    char section;

}

What will be the output of the following program?

public class College {

    public static void main(String[] args) {

        Student[] student = new Student[2];

        student[0] = new Student();

        student[0].name = “Khan”;

        student[0] = new Student();

        student[0].name = “Kittu”;

        student[1] = new Student();

        student[1].name = “Munna”;

        for (Student element : student) {

            System.out.print(element.name + ” ~ “);

        }

    }

}

class Student {

    String name;

}

______________________________________________________________________________________