+ 1
Accessing multidimensional array using scanner, it works with a single array but not multi?.
import java.util.Scanner; public class Program { public static void main(String[] args) { int array[][] = {10, 5, 7, 2},{20,4,17,12}; System.out.println("Choose a value between 0-4"); Scanner scan = new Scanner(System.in); int num = scan.nextInt(); int num2 = scan.nextInt(); int value = array[num][num2]; System.out.println(value + " < Your selected Value"); } }
2 ответов
+ 3
The problem isn't with accessing the array it's with initializing the array.
You use:
int array[][] = {10, 5, 7, 2},{20,4,17,12};
What should be:
int array[][] = {{10, 5, 7, 2},{20,4,17,12}};
Then it should work as expected.
+ 1
oh yeah i know this 😏 lol