Skip to main content

Sorting Three Number in JAVA.(without inbuilt function)

1 Logic CODING:
class sort1{
 public static void main(String ar[]){
  int a=70,b=19,c=33,temp;
  if(a>b){temp=a;a=b;b=temp;}
  if(b>c){temp=b;b=c;c=temp;}
  if(a>b){temp=a;a=b;b=temp;}
  System.out.print(a+" "+b+" "+c);
 }
}
2 Logic CODING:
class sorting{
 public static void main(String args[]){
   int a=24,b=12,c=38,temp;
   System.out.println(a + " " + b + " " + c);
   if(a>b){
    if(a>c){
     temp=c;
     c=a;
       if(temp>b){
         a=b;
         b=temp;
        }
       else{a=temp;}
     }
    else if(a<c){temp=a;a=b;b=temp;}
   }
   else if(b>c){
    temp=c;c=b;
     if(temp<a){
      b=a;a=temp;
     }
     else{
      b=temp;
     }
   }
  System.out.print(a + " " + b + " " + c);
 }
}

Comments