From a43803e1f1accd77da9478659c35cea07e9ce9d3 Mon Sep 17 00:00:00 2001 From: PC de clase Date: Thu, 24 Sep 2026 12:42:39 +0200 Subject: [PATCH] 24-9 --- src/AbonoRiego.java | 26 ++++++++++++++++++++++++++ src/Casting1.java | 12 ++++++++++++ src/Printf1.java | 6 ++++++ 3 files changed, 44 insertions(+) create mode 100644 src/AbonoRiego.java create mode 100644 src/Casting1.java create mode 100644 src/Printf1.java diff --git a/src/AbonoRiego.java b/src/AbonoRiego.java new file mode 100644 index 0000000..442ca8a --- /dev/null +++ b/src/AbonoRiego.java @@ -0,0 +1,26 @@ +import java.util.Scanner; + +void main() { + Scanner sc = new Scanner(System.in); + boolean llueve; + boolean sol; + int diasRiego; + int diasAbono; + + System.out.print("Está lloviendo? "); + llueve = sc.nextBoolean(); + sc.nextLine(); + System.out.print("Hace sol? "); + sol = sc.nextBoolean(); + sc.nextLine(); + System.out.print("Cuantos días hace que regaste? "); + diasRiego = sc.nextInt(); + sc.nextLine(); + System.out.print("Cuantos días hace que abonaste? "); + diasAbono = sc.nextInt(); + sc.nextLine(); + + boolean regar = !(llueve || diasRiego < 5 || sol); + boolean abonar = regar && diasAbono >= 10; + System.out.println("Regar: " + regar + "\nAbonar: " + abonar); +} \ No newline at end of file diff --git a/src/Casting1.java b/src/Casting1.java new file mode 100644 index 0000000..f2be42d --- /dev/null +++ b/src/Casting1.java @@ -0,0 +1,12 @@ +// Corregir y explicar errores + +public class Casting1 { + public static void main(String[] args) { + byte edadJuan=20; + int edadPedro=edadJuan+1; // La operación se defaultea a int + short sueldoBase= 1980; + short complementos= 400; + int sueldoTotal; + sueldoTotal=sueldoBase+complementos; // Esta expresión es int + } +} \ No newline at end of file diff --git a/src/Printf1.java b/src/Printf1.java new file mode 100644 index 0000000..6621439 --- /dev/null +++ b/src/Printf1.java @@ -0,0 +1,6 @@ +void main() { + // Imprimir 1234 justificado a la derecha, en un campo de 10 dígitos. + System.out.printf("%010d\n", 1234); + // Imprimir 3.333333 con un signo (+ o –) en un campo de 20 caracteres, con una precisión de 3 + System.out.printf("%+20.3f\n", 3.333333); +} \ No newline at end of file