diff --git a/Seminar 3/code/ThirdSeminar/.idea/.gitignore b/Seminar 3/code/ThirdSeminar/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Seminar 3/code/ThirdSeminar/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Seminar 3/code/ThirdSeminar/.idea/misc.xml b/Seminar 3/code/ThirdSeminar/.idea/misc.xml new file mode 100644 index 0000000..03f397c --- /dev/null +++ b/Seminar 3/code/ThirdSeminar/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Seminar 3/code/ThirdSeminar/.idea/modules.xml b/Seminar 3/code/ThirdSeminar/.idea/modules.xml new file mode 100644 index 0000000..23c9bfe --- /dev/null +++ b/Seminar 3/code/ThirdSeminar/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Seminar 3/code/ThirdSeminar/.idea/vcs.xml b/Seminar 3/code/ThirdSeminar/.idea/vcs.xml new file mode 100644 index 0000000..c2365ab --- /dev/null +++ b/Seminar 3/code/ThirdSeminar/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Seminar 3/code/ThirdSeminar/ThirdSeminar.iml b/Seminar 3/code/ThirdSeminar/ThirdSeminar.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Seminar 3/code/ThirdSeminar/ThirdSeminar.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Seminar 3/code/ThirdSeminar/out/production/ThirdSeminar/Main.class b/Seminar 3/code/ThirdSeminar/out/production/ThirdSeminar/Main.class new file mode 100644 index 0000000..32e8db5 Binary files /dev/null and b/Seminar 3/code/ThirdSeminar/out/production/ThirdSeminar/Main.class differ diff --git a/Seminar 3/code/ThirdSeminar/src/Main.java b/Seminar 3/code/ThirdSeminar/src/Main.java new file mode 100644 index 0000000..4b27ece --- /dev/null +++ b/Seminar 3/code/ThirdSeminar/src/Main.java @@ -0,0 +1,55 @@ +import java.util.*; + +public class Main { + public static void main(String[] args) { +// int[] array = generateArray(10); +// int[] array2 = array; +// +// System.out.println(array); +// System.out.println(array2); +// +// array2[0] = 10; +// +// printArray(array); +// System.out.println(); +// printArray(array2); + + int[] array = new int[]{0, 1, 1, 2, 0, 0, 510, 12, 5}; + + System.out.println(sumArray(array)); +// Arrays.sort(array); +// printArray(array); +// int index = Arrays.binarySearch(array, 400); //always call sort before binarySearch +// System.out.println(index); + } + + public static int sumArray(int[] array) { +// int sum = 0; +// for (int element : array) { +// sum += element; +// } + +// return sum; + return Arrays.stream(array).sum(); + } + + public static int[] generateArray(int size) { + int[] array = new int[size]; + for (int i = 0; i < size; i++) { + array[i] = i; + } + return array; + } + + public static void printArray(int[] array) { +// for (int element : array) { +// System.out.print(element + " "); //array[i] +// } + +// for(int i = 0; i < array.length; i++) { +// System.out.print(array[i] + " "); +// } + + System.out.println(Arrays.toString(array)); + } +} \ No newline at end of file