Saturday, February 11, 2017

sorting and displaying largest and smallest number- using java

import java.util.*;

public class labfour {

    public static void main(String a[]) {
        int v[] = new int[5];
        System.out.println("enter any five elements of the array");
        Scanner sc = new Scanner(System.in);
        v[0] = sc.nextInt();
        Scanner l = new Scanner(System.in);
        v[1] = l.nextInt();
        Scanner s = new Scanner(System.in);
        v[2] = s.nextInt();
        Scanner c = new Scanner(System.in);
        v[3] = c.nextInt();
        Scanner g = new Scanner(System.in);
        v[4] = g.nextInt();

        System.out.println("sorting the above array");
        for (int i = 0; i < v.length; i++) {
            for (int j = i + 1; j < v.length; j++) {
                if (v[i] > v[j]) {
                    int temp = v[i];
                    v[i] = v[j];
                    v[j] = temp;

                }

            }
            System.out.println(v[i]);

        }

        System.out.println("the smallest number is " + v[0]);
        System.out.println("the largest number is " + v[4]);

    }

}
output:

1 comment:

  1. Honees | Honees, No Brasil, No Brasil, No 메리트 카지노 쿠폰 메리트 카지노 쿠폰 planet win 365 planet win 365 william hill william hill 우리카지노 우리카지노 starvegad starvegad 11bet 11bet 314 Puyo puyo puyo | TaKe

    ReplyDelete