• Lenguaje

    Java usando Scanner

  • Descripción

    Se tiene un terreno A cuadrado que mide LADO metros por lado a un precio COSTOA por metro cuadrado y se tiene un terreno B rectangular que mide BASE metros de base y ALTURA metros de altura a un COSTOB por metro cuadrado. Elaborar un algorito que lea los datos de los dos terrenos e imprima cual es el más barato o si cuestan igual.

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

public class CostoDeTerrenos {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        double ALTURA, BASE, COSTOA, COSTOB, LADO;
        double terreno_A, terreno_B;
        System.out.print("Ingresa el valor de ALTURA: ");
        ALTURA = in.nextDouble();
        in.nextLine();
        System.out.print("Ingresa el valor de BASE: ");
        BASE = in.nextDouble();
        in.nextLine();
        System.out.print("Ingresa el valor de COSTOA: ");
        COSTOA = in.nextDouble();
        in.nextLine();
        System.out.print("Ingresa el valor de COSTOB: ");
        COSTOB = in.nextDouble();
        in.nextLine();
        System.out.print("Ingresa el valor de LADO: ");
        LADO = in.nextDouble();
        in.nextLine();
        terreno_A=LADO*LADO*COSTOA;
        terreno_B=BASE*ALTURA*COSTOB;
        if(terreno_A<terreno_B)
            System.out.println("El terrneo A es m\u00E1s barato.");
        if(terreno_A==terreno_B)
            System.out.println("Los terrenos cuestan igual.");
        if(terreno_A>terreno_B)
            System.out.println("El terrneo B es m\u00E1s barato.");
        System.out.println("Valor de terreno A: " + terreno_A);
        System.out.println("Valor de terreno B: " + terreno_B);
    }

}