• Lenguaje

    Java usando Scanner

  • Descripción

    Permite leer dos números y determina el mayor y el menor.

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
import java.util.Scanner;

public class MayorYMenorDeDosNumeros {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double a, b, mayor, menor;
        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();
        if(a>b)
        {
            mayor=a;
            menor=b;
        }
        else
        {
            mayor=b;
            menor=a;
        }
        System.out.println("Valor de mayor: " + mayor);
        System.out.println("Valor de menor: " + menor);
    }

}