Hi, I am pretty new on UIpath so I have have a lot of challenging on my learning.
There is an excercise called: Find the smallest and biggest numbers in an Array, but when I am trying to get the output, it show me the same number as min or max.
This is the output:
The minimum number is: 10
The maximum number is: 10
My thoughts are than the issue is in this section:
Here is the logic.
compare 1st item with 2nd is 1st item is greater then 2nd then assign 2nd index in Array to 1st item and increment i =i+1 and so on.
Hi,
Make sure that you change the ‘Type Argument’ of the ‘For Each’ in the Properties panel to Int32 , and create an Int32 variable (“Index”) to place in the ‘Output’ field.
I’ve attached the workflow that I’ve developed below. if you want, you can go thorough that. finding maximum and minimum number in the array.zip (1.7 KB)
Thanks
Hi Please find the solution as for min and max this can help you
public static void main(String args) {
int arr[]={7, 5, 2, 4, 3, 9};
int min=arr[0];
int max=0;
int index=0;
for (int a : arr ){
if (arr[index]<min) {
min=arr[index];
}
if (arr[index]>max) {
max=arr[index];
}
index++;
}
System.out.println(min);
System.out.println(max);
}
If I am reading your logic correctly, yes you would end up finding the largest number in the array, but this logic would also modify the original array.[quote=“Rajesh_Bhatt, post:7, topic:186211, full:true”]
Follow below steps.
Here is the logic.
compare 1st item with 2nd is 1st item is greater then 2nd then assign 2nd index in Array to 1st item and increment i =i+1 and so on.