@Zeune/

Multiplying an array

Java

Using for loop

fork
loading
Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Main {

  public static void main(String[] args) {

    int[] testVar = {3, 1, 43, 8, 2, 1};
    int result;

    for(int i = 0; i < testVar.length; i++){
      /*
      *
      * Multiplies an array by the currentLoop. E.g loopIndex * timesLooped
      */

      result = testVar[i] * i; 
      System.out.println(result);
    }
  }
}