Java Program to swap array elements divisible by 10 with next element.

Java Program to swap array elements divisible by 10 with next element.
For example, array contains 9,50,5,20,3,4
The array should become 9,5,50,3,20,4

import java.util.*;
public class onedimensionalarray3
{
public static void main(String[]args)
{
  int i;
  int a[]=new int[5];
  Scanner s=new Scanner(System.in);
  System.out.println("enter the value of array");
  for( i=0;i<5;i++)
    a[i]=s.nextInt();
  for(i=0;i<5;i++)
  {
   /*formula of swipe*/
   if(a[i]%10==0)
  {
    int t=a[i];
    a[i]=a[i+1];
    a[i+1]=t;
    i++;
}}
  System.out.println("swipe value are=");
  for(i=0;i<5;i++)
    System.out.println(a[i]);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *