diff --git a/src/MagidLab1.java b/src/MagidLab1.java new file mode 100644 index 0000000..e913453 --- /dev/null +++ b/src/MagidLab1.java @@ -0,0 +1,57 @@ +public class MagidLab1 { + public static int differenceBetweenLargestAndSmallest(int[] array) { + + if (array.length == 0) { + System.out.println("There was a problem with the array"); + } + + int largest = array[0]; + int smallest = array[0]; + + for (int i = 1; i < array.length; i++) { + if (array[i] > largest) { + largest = array[i]; + } + + if (array[i] < smallest) { + smallest = array[i]; + } + } + + return largest - smallest; + } + + // Lab1 ii + public static void findFirstAndSecondSmallest(int[] array) { + int min = array[0]; + int secondMin = array[0]; + for (int i = 1; i < array.length; i++) { + if (array[i] < min) { + secondMin = min; + min = array[i]; + } else if (array[i] < secondMin) { + secondMin = array[i]; + } + System.out.println(array[i]); + } + + } + +// Lab1 iii + + + public static double mathematicalProblems(double x, double y) { + double result = 0.0; + double xPow = x * x; + double loopVariable = 1; + for (int i = 0; i < 2; i++) { + loopVariable = loopVariable * (4 * y / 5 - x); + } + result = xPow + loopVariable; + return result; + + } +} + + + diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..b50fdba --- /dev/null +++ b/src/Main.java @@ -0,0 +1,15 @@ +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + //TIP Press with your caret at the highlighted text + // to see how IntelliJ IDEA suggests fixing it. + System.out.print("Hello and welcome!"); + + for (int i = 1; i <= 5; i++) { + //TIP Press to start debugging your code. We have set one breakpoint + // for you, but you can always add more by pressing . + System.out.println("i = " + i); + } + } +} \ No newline at end of file