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
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
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
Chemistry,
5 months ago
English,
5 months ago
Chemistry,
5 months ago
Social Sciences,
11 months ago
Math,
11 months ago
Biology,
1 year ago
Math,
1 year ago
Political Science,
1 year ago