jeudi 17 août 2017

Java code 1+ issue

problem with Java code.

import java.util.Random;

public class arrayTable {
public static void main (String[] args) {
    System.out.println("Index\t + Value");
    int Array[] = new int[10];

    Random Object = new Random();
    int Values;

    // Assigning random values to each element of array

    for(int i=0; i<Array.length;i++) {
        Values= (1+Object.nextInt(50));
        Array[i] = Values;
    }

    for(int j=0;j<Array.length;j++) {
        System.out.println(j + "\t" + Array[j]);
      }

    }
}

Here with this code i wrote (1+) next to the object so the index should start at 1, however when ever i run the code at always starts at index 0, and it does not matter if i type 2+ or 3+ pr whatever. Could anyone be helpful with pointing out the problem with the code.

thank you in advance.




Aucun commentaire:

Enregistrer un commentaire