Computer Science, asked by yash71, 1 year ago

write a program to input a single number of 3 digit and print the greatest and smallest digit (by java programming)

Answers

Answered by prakriti27
4
 import java.util.*;
class Digit
{
void main()
{
Scanner sn = new Scanner(System.in);       
System.out.print("Enter a three digit number:");       
int n = sn.nextInt();       
int min=10, max=0, m=n, r;       
while(m>0)       
{           
r=m%10;           
if(r<min)
{               
min=r;           
}           
m=m/10;       
}       
m=n;       
while(m>0)       
{           
r=m%10;           
if(r>max)           
{               
max=r;           
}           
m=m/10;       
}       
System.out.println("smallest digit: "+min);       
System.out.println("highest digit: "+max);   
}
}
Similar questions