Question

In: Computer Science

write a java program that takes three numbers from the user and print the greatest number...

write a java program that takes three numbers from the user and print the greatest number (using if-statement).

sample output:

input the first number:35

input the second number:28

input the third number:87

the greatest number:87

Solutions

Expert Solution

CODE:

import java.util.*;
public class Main
{
   public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Input the first number: ");
int num1 = sc.nextInt();

System.out.print("Input the second number: ");
int num2 = sc.nextInt();

System.out.print("Input the third number: ");
int num3 = sc.nextInt();
// Check if num1 is greater than other 2 numbers
if (num1 > num2)
if (num1 > num3)
System.out.println("The greatest number: " + num1);
// Check if num2 is greater than other 2 numbers
if (num2 > num1)
if (num2 > num3)
System.out.println("The greatest number: " + num2);
   // Check if num3 is greater than other 2 numbers
if (num3 > num1)
if (num3 > num2)
System.out.println("The greatest number: " + num3);
}
}

OUTPUT:

Input the first number: 35                                                                                                    

Input the second number: 28                                                                                                   

Input the third number: 87                                                                                                    

The greatest number: 87

SUMMARY:

The above code is written in java as instructed. First we scan the value from user by asking to input 3 numbers. Then using if statements we find the greatest of 3 numbers and print the output accordingly.

Note: If you have any queries please let me know in comments. If not than a Like would be appreciated


Related Solutions

how to write a cpp program that takes a number from a user, and print the...
how to write a cpp program that takes a number from a user, and print the sum of all numbers from one to that number on screen? using loop interation as basic as possible.
Write a program that will print the whole numbers from a user-specified minimum to a user-specified...
Write a program that will print the whole numbers from a user-specified minimum to a user-specified maximum. Display the total amount of numbers printed.
There are three things wrong with this program. List each. print("This program takes three numbers and...
There are three things wrong with this program. List each. print("This program takes three numbers and returns the sum.") total = 0 for i in range(3):     x = input("Enter a number: ")     total = total + i print("The total is:", x)
c# language Write a program that takes in a number from the user. Then it prints...
c# language Write a program that takes in a number from the user. Then it prints a statement telling the user if the number is even or odd. If the number is odd, it counts down from the number to 0 and prints the countdown on the screen, each number on a new line. If the number is even, it counts down from the number to 0, only even numbers. For example, if the user enters 5, the output will...
I need it in java. Write a program that will print if n numbers that the...
I need it in java. Write a program that will print if n numbers that the user will input are or not within a range of numbers. For that, your program needs to ask first for an integer number called N that will represent the number of times that will ask for other integer numbers. Right after, it should ask for two numbers that will represent the Min and Max for a range. Lastly. it will iterate N number times...
Write a Java program that takes an array of 10 "Int" values from the user and...
Write a Java program that takes an array of 10 "Int" values from the user and determines if all the values are distinct or not. Return TRUE if all the values of the array are distinct and FALSE if otherwise.
Java Write a program that reads 4 integer numbers from the user combine it into a...
Java Write a program that reads 4 integer numbers from the user combine it into a single number. You need to ask the user to first specify how to combine the numbers (forward or backward). Note that for the backward option you need to check that the last digits should be 0, also for the forward option you need to check that the fist digit is not 0. Use for loops and switch for the menu.                       4. Write an application...
1. Write a Java program that prompts the user to enter three integer numbers. Calculate and...
1. Write a Java program that prompts the user to enter three integer numbers. Calculate and print the average of the numbers. 2. Write a Java program that uses a for loop to print the odd numbers from 1 to 20. Print one number per line in the command line window. 3. Write a program which asks the user to input the size of potatoe fries she would like to purchase, and based on the size, it will tell her...
2. Write a c++ program that takes from the user the ​number of courses​ and constructs...
2. Write a c++ program that takes from the user the ​number of courses​ and constructs 3 ​dynamic 1D arrays​ with size courses+1. Each array represents a student. Each cell in the array represents a student’s mark in a course. In the last cell of each 1D array you should calculate the average mark of that student. Then output the average mark of all students in each course. Delete any allocated memory. Example Number of courses : 4 50 60...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them into a Text File. The inputs are Student Name, Student Address and student Date of Birth. Also write a simple program that reads and display the input from the first program text file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT