REMOVE ZERO FROM A NUMBER IN ARRAY JAVA

 EASILY REMOVE ZEROS FROM ANY NUMBER IN JAVA

USE THE .LENGTH PROCESS HERE

import java.util.*;

public class remove_zero

{

 void main()

 {

  Scanner ob=new Scanner(System.in);

  int a[]= new int[6],i;

  System.out.println("Enter the elements");

  for(i=0;i<6;i++)

  {

   a[i]=ob.nextInt();

   }

   

   int j=0;

   for( i=0;i<a.length;i++)

   {

    if(a[i]!=0)

    {

     a[j]=a[i];

     j++;

     }

     }

     System.out.println("The elements are");

     for( i=0;i<j;i++)

     System.out.println(a[i]);

     }

     }


Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

It looks like you're using an ad blocker. We rely on ads to keep our site free, please whitelist us!

Click here to continue

Please whitelist our site to continue enjoying our content.

Whitelist | Close