From 49dc1765a1d7842efb83e4b1ae7665d015ce3e9f Mon Sep 17 00:00:00 2001 From: Yusif Xankisiyev Date: Wed, 18 Feb 2026 17:18:43 +0400 Subject: [PATCH] Solved loops exercises --- .idea/.gitignore | 10 ++++ .idea/compiler.xml | 13 +++++ .idea/encodings.xml | 7 +++ .idea/jarRepositories.xml | 20 ++++++++ .idea/lab-java-loops-and-version-control.iml | 9 ++++ .idea/misc.xml | 14 ++++++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 +++ src/pom.xml | 17 +++++++ src/src/main/java/com/ironhack/Main.java | 50 +++++++++++++++++++ src/target/classes/com/ironhack/Main.class | Bin 0 -> 1910 bytes 11 files changed, 154 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/lab-java-loops-and-version-control.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 src/pom.xml create mode 100644 src/src/main/java/com/ironhack/Main.java create mode 100644 src/target/classes/com/ironhack/Main.class diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..2612326 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..4bbba5b --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/lab-java-loops-and-version-control.iml b/.idea/lab-java-loops-and-version-control.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/lab-java-loops-and-version-control.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b65bd70 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..dfda522 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/pom.xml b/src/pom.xml new file mode 100644 index 0000000..e60ee47 --- /dev/null +++ b/src/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + com.ironhack + src + 1.0-SNAPSHOT + + + 17 + 17 + UTF-8 + + + \ No newline at end of file diff --git a/src/src/main/java/com/ironhack/Main.java b/src/src/main/java/com/ironhack/Main.java new file mode 100644 index 0000000..26161ff --- /dev/null +++ b/src/src/main/java/com/ironhack/Main.java @@ -0,0 +1,50 @@ +package com.ironhack; + +public class Main { + public static void main(String[] args) { + System.out.println(method(2,5)); + int[] arr = {1,1,3,4,5}; + findTwoSmallest(arr); + } + + public static int arrayRange(int[] arr) { + if (arr == null || arr.length == 0) { + throw new IllegalArgumentException("The length of the array must be at least 1"); + } + + int min = arr[0]; + int max = arr[0]; + + for (int i = 1; i < arr.length; i++) { + if (arr[i] < min) min = arr[i]; + if (arr[i] > max) max = arr[i]; + } + + return max - min; + } + + public static void findTwoSmallest(int[] arr) { + if (arr == null || arr.length == 0) { + throw new IllegalArgumentException("The length of the array must be at least 1"); + } + + int smallest = Integer.MAX_VALUE; + int secondSmallest = Integer.MAX_VALUE; + + for (int num : arr) { + if (num < smallest) { + secondSmallest = smallest; + smallest = num; + } else if (num < secondSmallest && num != smallest) { + secondSmallest = num; + } + } + + System.out.println("Smallest: " + smallest); + System.out.println("Second Smallest: " + secondSmallest); + } + + public static int method(int x, int y){ + return (x*x) + (((4*y/5) - x) * ((4*y/5) - x)); + } +} \ No newline at end of file diff --git a/src/target/classes/com/ironhack/Main.class b/src/target/classes/com/ironhack/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..2e68c6e2412237288aa5691e845cd809de4b5e13 GIT binary patch literal 1910 zcmaJ?K~Eb;6#j;_cWvVUF*s>31Sce^almfVmL{7EhI(nc z>6r~`IV~E+i@qbv$=-1-+bemlDI2*6`p|D+Ac~WS37o7rjjZK5c1>0`vrE#liPkW^ zno|`BrV53LLIgvI8#ookX}l#cc#Ky8V@qMwX&p!vCe{?na1;rQ2=sqx+11sroKi#9 z>t>UY1yk$PF>qGk{2|!_Pd8+J&fRD=OxwHlxMFU3mScyI6iCgvuG~>1_umacqx) zCZ(6Go00;@Hj`%ER92Y?MsZ$ca-11RwNv2dlKd@uBd2gLl6M!b?U@^X799i;0D z^sE;IB3#PtyX-B7;g^9zVR3NQ8mjtQLp~NbQS#UjOLD6doo2V#SfS?Y8um3!)}eY( zR0CJ(goa|9C?%)mR?G!UkqxV+%BXa+S8qCw*YsSuwdA*0vtP%j5!^=6z>-S)vcQGI z%2@UzXVc8KE7z{Xf~k5TW= zY5PLvx~t!DG0)~MS)Q2-;f_G>L0+yWMF@9U@{*sfWS3kZTCi=?ov+Jg(`*{JCvfoy z`QtblxG!+_|5bU7+X=uq-o+mFHFzmlbm;tMxXW@DN}7HS@go;K6v00RG`z!gw5@=5 zafQ1u-oyJH;~E0K)6`Eef}s~U@eG5ZUm|5Kuu=|i1of4&Zmg7z&`R<03!FLhAETuT zrI$$KFz_~?Glg}k?GGPdn!9moe2A+=3*#EDcTj(0T*`Vr{X0VGy>D^iXN;C(W6yE! z*R+<&bIb&0N7H*d7)y_45<4(BO4)bd$;^`=+5E{8BzBocJi}$KM|LsguT{?56t9pPh^!G?$60>INFs>~Y>qTn z(ofmNLP_|=xVr!IiIeMySVw9?kEELinD=vA^Z>UFNVcS z^!?+L=YLLz{9>nphK7f0Mxqv~4_7-=?F&_#?q;0qYLFp(OgQx$!Yw}p4GX^hCs^dH Wdc8o5761DgN|Z&oU&R{3Kl2||H<-Zy literal 0 HcmV?d00001