• Lenguaje

    Java usando Scanner

  • Descripción

    Sumar el número mayor y el número menor de 4 números ingresados.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.Scanner;

public class SumaDelMenorYMayorDe4Numeros {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double a, b, c, d, mayor;
        double menor, suma;
        System.out.print("Ingresa el valor de a: ");
        a = in.nextDouble();
        in.nextLine();
        System.out.print("Ingresa el valor de b: ");
        b = in.nextDouble();
        in.nextLine();
        System.out.print("Ingresa el valor de c: ");
        c = in.nextDouble();
        in.nextLine();
        System.out.print("Ingresa el valor de d: ");
        d = in.nextDouble();
        in.nextLine();
        if(a>b)
        {
            mayor=a;
            menor=b;
        }
        else
        {
            mayor=b;
            menor=a;
        }
        if(mayor<c)
            mayor=c;
        if(mayor<d)
            mayor=d;
        if(menor>c)
            menor=c;
        if(menor>d)
            menor=d;
        suma=mayor+menor;
        System.out.println("Valor de mayor: " + mayor);
        System.out.println("Valor de menor: " + menor);
        System.out.println("Valor de suma: " + suma);
    }

}