Wednesday, January 16, 2008

Smallest and Largest Digit present in a Number

Topic says the question


import java.io.*;
class LSdigits
{
public static void main(String args[])throws IOException
{
int i,x,num,n,l,h;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" Enter any Number ");
num=Integer.parseInt(br.readLine());
n=num;
h=0;l=9;
do
{
x=n%10;
if(x>h)
h=x;
if(xl=x;
n=n/10;
}while(n>0);
System.out.println("Largest number = "+h+" Lowest number = " + l);
}
}

No comments: