“Dostęp do elementów macierzy Java za pomocą pętli” Kod odpowiedzi

Dostęp do elementów macierzy Java za pomocą pętli


// Create an array with room for 100 integers
int[] nums = new int[100];

// Fill it with numbers using a for-loop
for (int i = 0; i < nums.length; i++)
    nums[i] = i + 1;  // +1 since we want 1-100 and not 0-99

// Compute sum
int sum = 0;
for (int n : nums)
    sum += n;

// Print the result (5050)
System.out.println(sum);

Attractive Addax

Dostęp do elementów macierzy Java za pomocą pętli

class ArrayUsingLoop
{
    public static void main (String[] args)
    {        
      int[] newArray;
         
      newArray= new int[5];
         
      newArray[0] = 1;
      newArray[1] = 2;
      newArray[2] = 3;
      newArray[3] = 4;
      newArray[4] = 5;
         
      for (int i = 0; i < newArray.length; i++)
         System.out.println("Array Element at index " + i +
                                      " : "+ newArray[i]);         
    }
}
Unsightly Unicorn

Odpowiedzi podobne do “Dostęp do elementów macierzy Java za pomocą pętli”

Pytania podobne do “Dostęp do elementów macierzy Java za pomocą pętli”

Więcej pokrewnych odpowiedzi na “Dostęp do elementów macierzy Java za pomocą pętli” w TypeScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu