Computer Science, asked by hemanthprabhu2003, 11 months ago

21. A list Num contains the following elements:
3, 25, 13, 6, 35, 8, 14, 45
Write a function to swap the content with the next value divisible by 5 so that the resultant list will
look like:
25, 3, 13, 35, 6, 8, 45, 14​

Answers

Answered by akshayamca14
7

Answer:

public class Main

{

public static void main(String[] args)

{

       int [] numbers=new int[]{3, 25, 13, 6, 35, 8, 14, 45};

       Swap(numbers);

}

public static void Swap(int[] numbers)

{

    for (int i=0;i<= numbers.length-1 ;i++ )

    {

        if(numbers[i] % 5==0)

        {  

            int temp;

            temp=numbers[i];

            numbers[i]=numbers[i-1];

            numbers[i-1]=temp;

        }

    }

    for (int i=0;i<= numbers.length-1 ;i++ )

    {

        System.out.print(numbers[i]+",");

    }

}

}

Explanation:

Enjoyyyyyyyyy!!!

Answered by mg733189
6

Answer:

num =[3,25,13,6,35,8,14,45]

for i in range(len(num)):

if num[i]%5==0:

num[i-1],num[i]=num[i],num[i-1]

print("The required answer :",num)

Explanation:

Try this

Similar questions