« Voici quelques exemples de choses intéressantes que tu peux faire avec les tableaux : »

Exemple 1.
Remplit un tableau de 10 éléments avec des nombres de 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] = i + 1;
        }
    }
}
Remplit un tableau de 10 éléments avec des nombres de 10 à 1 :
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;
        }
    }
}
Remplit un tableau de 10 éléments avec des nombres de 0 à 9 :
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;
        }
    }
}
Remplit un tableau de 10 éléments avec des nombres de 9 à 0 :
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;
        }
    }
}
Exemple 2.
Lit 10 chaînes saisies au clavier :
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();
     }
  }
}
Lit 10 nombres saisis au clavier :
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);
    }
  }
}
Exemple 3.
Affiche un tableau à l'écran :
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]);
    }
}
Exemple 4.
Initialisation rapide (statique). Ajoute des éléments de tableau :
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);
    }
}
Exemple 5.
Trouve le plus petit élément dans un tableau :
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);
    }
}