-
Notifications
You must be signed in to change notification settings - Fork 0
/
PA3.java
61 lines (40 loc) · 1.55 KB
/
PA3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package csc_assignment;
import java.util.*;
public class PA3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner (System.in);
ArrayList<ArrayList<Integer>> data = new ArrayList<ArrayList<Integer>>();
System.out.println("How many lists: ");
int lists = scan.nextInt();
scan.nextLine();
for (int i = 0; i < lists; i ++){
System.out.println("Please enter how many numbers you want in the list, followed by those numbers: ");
String[] input = scan.nextLine().split(" ");
int count = Integer.parseInt(input[0]);
ArrayList<Integer> num = new ArrayList<Integer>();
for (int a = 1 ; a <= count ; a ++){
int x = Integer.parseInt(input[a]);
num.add(x);
}
data.add(num);
}
System.out.println("How many indexes: ");
int indexes = scan.nextInt();
scan.nextLine();
for(int t = 0; t < indexes; t++){
try {
System.out.println("What is the position? ");
String[] line = scan.nextLine().split(" ");
int first = Integer.parseInt(line[0]);
int second = Integer.parseInt(line[1]);
ArrayList<Integer> in = data.get(first-1);
int out = in.get(second-1);
System.out.println(out);
}catch(Exception e ) {
System.out.println("Error!");
}
}
scan.close();
}
}