write a program to input a single number of 3 digit and print the greatest and smallest digit (by java programming)
Answers
Answered by
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);
}
}
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
Math,
8 months ago
Math,
8 months ago
English,
8 months ago
Social Sciences,
1 year ago
Social Sciences,
1 year ago
Chemistry,
1 year ago
Math,
1 year ago