Find the smallest and biggest numbers in an Array

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:

Does anyone knows where the problem is?

Thanks to all!

Hi,

For now, can you check the following?

  1. Check Scope of max and min variable. These scope should be wider than For Each.
  2. Assign activity in “If array(index)<min” should be min =Array(index).

Regards,

Hi,
Can someone share the complete solution for this practise session,as i am new to this i am facing lot of issues.

Thanks

1 Like

Where is your Index value initiated ? and where you are making it incremented ?
can you check once.

What values are assigned to TypeArgument and Output in the For Each activity? Could you share variables used?

This is my answer. With the help from this link.

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.

Regards,
Rajesh

1 Like

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 go through this
finding maximum and minimum number in the array.zip (1.7 KB)
Thanks

1 Like

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.

Regards,
Rajesh
[/quote]

1 Like

grafik

arr1.Min()
arr1.Max()
1 Like