4-5 max and min
Post date: Feb 8, 2014 4:59:32 PM
// this program to find maximun and minimum number
package javaapplication27;
import java.util.Scanner;
public class JavaApplication27 {
public static void main(String[] args) {
// TODO code application logic here
int number,max,min;
// input the number
System.out.print("input the number:");
Scanner k=new Scanner(System.in);
number=k.nextInt();
// to find the max and min
max=min=number%10; // This takes the first number to max and min
while(number!=0)
{
if(number %10>max) // this if to find max number
max=number%10;
if(number %10<min )
min=number%10;
number=(int)(number/10);
}
System.out.println("min="+min+"max="+max);
}
}