+ 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"); } }

22nd Jul 2017, 7:16 AM
D_Stark
D_Stark - avatar
2 odpowiedzi
+ 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.
22nd Jul 2017, 8:04 AM
ChessMaster
ChessMaster - avatar
+ 1
oh yeah i know this 😏 lol
22nd Jul 2017, 8:11 AM
D_Stark
D_Stark - avatar