"आपण अॅरेसह करू शकता अशा मनोरंजक गोष्टींची येथे काही उदाहरणे आहेत:"

उदाहरण १.
1 ते 10 पर्यंतच्या संख्येसह 10-घटक अॅरे भरा:
public class MainClass
{
    public static void main(String[] args)
    {
        int[] numbers = new int[10];

        for (int i = 0; i < numbers.length; i++)
        {
           numbers[i] = i + 1;
        }
    }
}
10 ते 1 पर्यंतच्या संख्येसह 10-घटक अॅरे भरा:
public class MainClass
{
    public static void main(String[] args)
    {
        int[] numbers = new int[10];

        for (int i = 0; i < numbers.length; i++)
        {
           numbers[i] = 10 - i;
        }
    }
}
0 ते 9 पर्यंतच्या संख्येसह 10-घटक अॅरे भरा:
public class MainClass
{
    public static void main(String[] args)
    {
        int[] numbers = new int[10];

        for (int i = 0; i < numbers.length; i++)
        {
           numbers[i] = i;
        }
    }
}
9 ते 0 पर्यंतच्या संख्येसह 10-घटक अॅरे भरा:
public class MainClass
{
    public static void main(String[] args)
    {
        int[] numbers = new int[10];

        for (int i = 0; i < numbers.length; i++)
        {
           numbers[i] = 9 - i;
        }
    }
}
उदाहरण २.
कीबोर्डवरील 10 स्ट्रिंग वाचा:
public class MainClass
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String[] list = new String[10];

    for (int i = 0; i < list.length; i++)
    {
      list[i] = reader.readLine();
     }
  }
}
कीबोर्डवरून 10 अंक वाचा:
public class MainClass
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int[] list = new int[10];

    for (int i = 0; i < list.length; i++)
    {
      String s = reader.readLine();
      list[i] = Integer.parseInt(s);
    }
  }
}
उदाहरण ३.
स्क्रीनवर अॅरे प्रदर्शित करा:
public class MainClass
{
    public static void main(String[] args) throws IOException
    {
        int[] list = new int[10];

        // Fill the array
        for (int i = 0; i < list.length; i++)
           list[i] = i;

        // Display the contents of the array
        for (int i = 0; i < list.length; i++)
          System.out.println(list[i]);
    }
}
उदाहरण ४.
द्रुत (स्थिर) आरंभीकरण. अॅरे घटक जोडा:
public class MainClass
{
    public static void main(String[] args) throws IOException
    {
        // Static initialization
        int[] list = {5, 6, 7, 8, 1, 2, 5, -7, -9, 2, 0};

        // Calculate the sum
        int sum = 0;
        for (int i = 0; i < list.length; i++)
           sum += list[i];

        System.out.println("Sum is " + sum);
    }
}
उदाहरण 5.
अॅरेमधील सर्वात लहान घटक शोधा:
public class MainClass
{
    public static void main(String[] args) throws IOException
    {
        int[] list = {5, 6, 7, 8, 1, 2, 5, -7, -9, 2, 0};

        int min = list[0];
        for (int i = 1; i < list.length; i++)
        {
             if (list[i] < min)
                  min = list[i];
        }

       System.out.println ("Min is " + min);
    }
}

कोडजिम युनिव्हर्सिटी कोर्सचा एक भाग म्हणून मार्गदर्शकासह व्याख्यान स्निपेट. पूर्ण अभ्यासक्रमासाठी साइन अप करा.