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 } } }
Click here to view the exercise solution
Share it on your social media and challenge your friends to solve programming problems. Together, we can learn and grow.
The code has been successfully copied to the clipboard.
Continue improving your Java programming skills with our selection of practical exercises from the lesson. Click on Practice and challenge your knowledge!
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.
Free programming course with practical exercises and solutions in C#. Start learning right now!
Take your Exercises C# lessons everywhere with our Android app. Download it now from Google Play
Own and third party cookies to improve our services. If you go on surfing, we will consider you accepting its use.