GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — hackerrank-java/src/JavaList.java at master · anishLearnsToCode/hackerrank-java Expand file tree/ Copy pathJavaList.javaMore file actions 41 lines (35 loc) · 1.17 KB / Copy pathJavaList.javaFile metadata and controls41 lines (35 loc) · 1.17 KB 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 // https://www.hackerrank.com/challenges/java-list/problem import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class JavaList { private static final Scanner SCANNER = new Scanner(System.in); public static void main(String[] args) { int length = SCANNER.nextInt(); List<Integer> list = new ArrayList<>(); for (int index = 0 ; index < length ; index++) { list.add(SCANNER.nextInt()); } int queries = SCANNER.nextInt(); runQueries(queries, list); print(list); } private static void print(List<Integer> list) { for (int element : list) { System.out.print(element + " "); } } private static void runQueries(int queries, List<Integer> list) { while (queries-- > 0) { String action = SCANNER.next(); if (action.equals("Insert")) { int index = SCANNER.nextInt(); int value = SCANNER.nextInt(); list.add(index, value); } else { // "Delete" int index = SCANNER.nextInt(); list.remove(index); } } } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |