jeudi 13 mai 2021

sort 3 numbers by using only conditional statemest java [closed]

package area;  // iam new programmer i want review this code please !

import java.util.Locale;
import java.util.Scanner;

public class Area {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in).useLocale(Locale.US);
        System.out.println("welcome to program for sort number");
        
        float x = input.nextFloat();
        float y = input.nextFloat();
        float z = input.nextFloat();
        
       if (x<y && x<z && y<z) {
           System.out.println(x);
           System.out.println(y);
           System.out.println(z);
       } else if (x<y && x<z && z<y) {
           System.out.println(x);
           System.out.println(z);
           System.out.println(y);
       } else if (y<x && y<z && x<z ) {
           System.out.println(y);
           System.out.println(x);
           System.out.println(z);
       } else if (y<x && y<z && z<x  ) {
           System.out.println(y);
           System.out.println(z);
           System.out.println(x);
       } else if (z<x && z<y && x<y ) {
           System.out.println(z);
           System.out.println(x);
           System.out.println(y);
       } else if (z<x && z<y && y<x ) {
           System.out.println(z);
           System.out.println(y);
           System.out.println(x);
       }
            
        System.out.println("i complete this program \nbye !");
        
        
    }

}

what do you think about my solution ?

Aucun commentaire:

Enregistrer un commentaire