A simple program to differentiate the Zeros and non zeros value from a complete number.
public class DiffZeroNonZero{
public static void main(String[] args){
long no;
try{
no = Long.parseLong(args[0]);
}catch(ArrayIndexOutOfBoundsException ex){
System.out.println("Please provide proper number as argument....");
return;
}
long tmp_z=0,tmp_nz=0,a;
int count_z=0,count_nz=0;
int pos_z = 0;
int pos_nz = 0;
System.out.println("\n\nEntered Nuber Is :-> " + no);
//Storing the number for future use.....
tmp_z = no;
tmp_nz = no;
//Getting the number of zeros and non_zeros from whole number.....
while(no>0){
a = no%10;
if(a!=0)
count_nz++;
else
count_z++;
no=no/10;
}
long zeros[] = new long[count_z];
long non_zeros[] = new long[count_nz];
//Storing the values of zeros and non_zeros in different arrays....
while(tmp_nz>0){
a = tmp_nz%10;
if(a!=0){
non_zeros[pos_nz++]=a;
}
tmp_nz=tmp_nz/10;
}
while(tmp_z>0){
a = tmp_z%10;
if(a!=0){
}else{
zeros[pos_z++]=a;
}
tmp_z=tmp_z/10;
}
//Printing both the arrays to user.....
System.out.print("\n\n Zeros :->" + java.util.Arrays.toString(zeros));
System.out.print("\n\n Non Zeros :->" + java.util.Arrays.toString(non_zeros));
}
}