Resolves Java 1D Array Task
This commit is contained in:
parent
fd890ab974
commit
4d6be24f49
3 changed files with 58 additions and 1 deletions
|
@ -0,0 +1,24 @@
|
|||
package eu.ztsh.training.hackerrank.datastructures.array_1d;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
// https://www.hackerrank.com/challenges/java-1d-array-introduction/problem
|
||||
public class Solution {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
int n = scan.nextInt();
|
||||
int[] a = new int[n];
|
||||
int index = 0;
|
||||
while (scan.hasNext()) {
|
||||
a[index] = scan.nextInt();
|
||||
index++;
|
||||
}
|
||||
scan.close();
|
||||
// Prints each sequential element in array a
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
System.out.println(a[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package eu.ztsh.training.hackerrank.datastructures.array_1d;
|
||||
|
||||
import java.util.List;
|
||||
import eu.ztsh.training.hackerrank.HackerRankTest;
|
||||
import eu.ztsh.training.hackerrank.SolutionClassDescription;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("HackerRank challenges: Java 1D Array")
|
||||
class SolutionTest extends HackerRankTest {
|
||||
|
||||
@Test
|
||||
public void testCase0() {
|
||||
simpleAssert(
|
||||
List.of("5", "10", "20", "30", "40", "50"),
|
||||
List.of("10", "20", "30", "40", "50")
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCase1() {
|
||||
simpleAssert(
|
||||
List.of("3", "100", "200", "100"),
|
||||
List.of("100", "200", "100")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SolutionClassDescription getSolutionClassDescription() {
|
||||
return new SolutionClassDescription(Solution.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@ import eu.ztsh.training.hackerrank.SolutionClassDescription.FieldModifier;
|
|||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@DisplayName("HackerRank chalenges: Java Priority Queue")
|
||||
@DisplayName("HackerRank challenges: Java Priority Queue")
|
||||
class SolutionTest extends HackerRankTest {
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue