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)
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.
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.
IN JAVA Write a complete program that asks the user to enter two real numbers from...
IN JAVA Write a complete program that asks the user to enter two real numbers from the console. If both numbers are positive print the product, if both numbers are negative print the quotient, otherwise print INVALID INPUT. Use a nested if; output should be to a dialog and console; use printf to format the console output (for real numbers specify the width and number of digits after the decimal). The output must be labeled. Follow Java conventions, indent your...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT