Write a Java program that prompts the user to enter three numbers (x, y, z) and determines which of them is the largest number. Then, display that number on the screen.
6 12 19
19
import java.util.Scanner; public class LargestThreeNumbers { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the first number (x): "); int x = input.nextInt(); System.out.print("Enter the second number (y): "); int y = input.nextInt(); System.out.print("Enter the third number (z): "); int z = input.nextInt(); if (x > y && x > z) { System.out.println(x); } else if (y > x && y > z) { System.out.println(y); } else if (z > x && z > y) { System.out.println(z); } else { System.out.println(x); // Equally large } } }
Haz clic aquí para ver la solución del ejercicio
Compártelo en tus redes sociales y desafía a tus amigos a resolver problemas de programación. Juntos, podemos aprender y crecer.
El codigo se ha copiado correctamente en el portapapeles.
Continua mejorando tus habilidades de programación en Java con nuestra selección de ejercicios prácticos de la lección. ¡Haz clic en Practicar y desafía tus conocimientos!
Java basic calculator. Input numbers and operators (+, -, x, /) for calculation. If the symbol is not valid, it displays 'Character not recognized'.
Calculate and display the absolute value of a number in Java with this programming exercise on conditions.
Basic calculator with switch for mathematical operations. Allows decimal numbers and error handling. Practice your skills in Java.
Learn Java: Detect whether a number is positive or negative in this programming exercise. Enhance your Java skills.
Create a Java program that prompts the user for a letter (x) and checks whether it is a vowel or any other symbol.
Create a Java program that uses the conditional operator to assign value to a boolean variable.
Java exercise to find the largest number among three and practice Java conditions.
Create a Java program that prompts the user to enter two integers (a, b) and determines how many of them are positive using nested conditional operators in Java.
Calculate a student's grade using a switch statement in Java based on an integer input. Practice using switch, break, and default.
Practice with exercises in Java related to the conditions, loops and structures of the language.
Curso de programación gratuito con ejercicios y soluciones prácticas en C#. ¡Comienza a aprender ahora mismo!
Lleva tus lecciones de Exercises C# a todas partes con nuestra aplicación para Android. Descárgala ahora desde Google Play.
Utilizamos cookies propias y de terceros para mejorar nuestros servicios. Si continua navegando, consideramos que acepta su uso.