Take 10 numbers in an array and show the numbers having at least one zero in them
E.G: input values 23 205 54 ……
Output would be 205……….
import java.io.*;
class ab
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int arr[]=new int [10];
void show() throws Exception
{
int n;
for(int i=0;i<10;i++)
{
System.out.println("\nEnter Value: ");
arr[i]=Integer.parseInt(br.readLine());
}
System.out.println("\nOriginal Value");
for(int i=0;i<10;i++)
{
System.out.print(" "+arr[i]);
}
System.out.println("\nValues with atleast single zero");
for(int i=0;i<10;i++)
{
n=arr[i];
if(zero(n))
System.out.print(" "+arr[i]);
}
}
private boolean zero(int n)//205
{
while(n>0)
{
if(n%10==0)
break;
n=n/10;
}
if(n==0)
return false;
else
return true;
}
public static void main(String args[]) throws Exception
{
ab obj=new ab();
obj.show();
}
}
No comments:
Post a Comment