"మీరు శ్రేణులతో చేయగల ఆసక్తికరమైన విషయాల యొక్క కొన్ని ఉదాహరణలు ఇక్కడ ఉన్నాయి:"

ఉదాహరణ 1.
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;
        }
    }
}
ఉదాహరణ 2.
కీబోర్డ్ నుండి 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);
    }
  }
}
ఉదాహరణ 3.
స్క్రీన్‌పై శ్రేణిని ప్రదర్శించండి:
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]);
    }
}
ఉదాహరణ 4.
త్వరిత (స్టాటిక్) ప్రారంభించడం. శ్రేణి మూలకాలను జోడించండి:
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);
    }
}

కోడ్‌జిమ్ విశ్వవిద్యాలయం కోర్సులో భాగంగా మెంటర్‌తో ఉపన్యాస స్నిప్పెట్. పూర్తి కోర్సు కోసం సైన్ అప్ చేయండి.