About 69,400 results
Open links in new tab
  1. Assigning values of an array in a for loop java - Stack Overflow

    Jul 15, 2012 · I'm basically hoping to create an array, then assign values to that array in a for loop. The code I have at the moment is: int i; int[] testarray = new int[50]; for (i = 0; i <=50; i++) { …

  2. Java Loop Through an Array - W3Schools

    Loop Through an Array. You can loop through the array elements with the for loop, and use the length property to specify how many times the loop should run. The following example outputs …

  3. how to get average using for loop in java? - Stack Overflow

    Mar 6, 2021 · how can I get average while using for loop in java. Here is what I have tried: System.out.println("Enter number "); . sum = sum + sc.nextInt(); . int avg = sum/10; . You're on …

  4. Java: Array with loop - Stack Overflow

    Jun 6, 2016 · To populate the array: numbers[i] = i+1; and then to sum it: ans += numbers[i]; or in short, if you want the sum from 1 to n: ( n ( n +1) ) / 2. If your array of numbers always is …

  5. JavaLoop Through an Array - GeeksforGeeks

    Dec 2, 2024 · In Java, looping through an array or Iterating over arrays means accessing the elements of the array one by one. We have multiple ways to loop through an array in Java. …

  6. Java Program to Iterate Over Arrays Using for and for-each Loop

    Nov 26, 2024 · In the below example, we will demonstrate how to iterate through an array using both the traditional for loop and the simplified for-each loop. Example: Explanation: Here, both …

  7. Java For Loop - GeeksforGeeks

    Apr 17, 2025 · The for loop in Java provides an efficient way to iterate over a range of values, execute code multiple times, or traverse arrays and collections. Now let’s go through a simple …

  8. Iterate Java Array using For Loop - Examples - Tutorial Kart

    To traverse through Java Array elements, you can use For Loop or Enhanced For Loop. In this tutorial, we write Java Programs using For Loop and Enhanced For Loop to iterate over Java …

  9. Average of N Numbers in Java using For loop | While loop | Array

    Jan 13, 2023 · In this article, you will learn how to find the average of N numbers in java using For loop, While loop, and Array. Example Enter the number of elements to calculate the average::

  10. Java For Loop (with Examples) - HowToDoInJava

    Nov 20, 2023 · Java for-loop statement is used to iterate over the arrays or collections using a counter variable that is incremented after each iteration. The for statement provides a compact …

Refresh