0

I have 3 arrays of integer for example:

int[] l1 = {1,2,3};
int[] l2 = {4,5,6};
int[] l3 = {7,8,9};

and I have an integer witch shows me a number between 1 to 3 , I want know how to relate this number to arrays I mean if it was 2 then chose the second array to work with

0

2 Answers 2

1

If I understood you correctly, one option might be to have a multidimensional array along the following lines:

    int[][] array = {{1,2,3}, {4,5,6}, {7,8,9}};

    int[] subArray = array[2];

    System.out.println(Arrays.toString(subArray));
Sign up to request clarification or add additional context in comments.

Comments

0

You can use 2D-Array to do that;

import java.util.Arrays;

public class Solution {
    public static void main(String[] args) {
        int choice = 2;
        int[] l1 = {1,2,3};
        int[] l2 = {4,5,6};
        int[] l3 = {7,8,9};
        int[][] toChoose = new int[3][];
        toChoose[0] = l1;
        toChoose[1] = l2;
        toChoose[2] = l3;
        System.out.println(Arrays.toString(toChoose[1]));
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.