4-5 max and min

posted Feb 8, 2014, 8:59 AM by dldar masud   [ updated Feb 8, 2014, 8:59 AM by Karwan Jacksi ]


// 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);
       
    }
}

ċ
JavaApplication27.java
(1k)
Karwan Jacksi,
Feb 8, 2014, 8:59 AM
Comments