write a program in Java to accept 3 integer parameters and print the largest of these numbers.
Answers
public class Biggest_Number
{
public static void main(String[] args)
{
int x, y, z;
Scanner s = new Scanner(System.in);
System.out.print("Enter the first number:");
x = s.nextInt();
System.out.print("Enter the second number:");
y = s.nextInt();
System.out.print("Enter the third number:");
z = s.nextInt();
if(x > y && x > z)
{
System.out.println("Largest number is:"+x);
}
else if(y > z)
{
System.out.println("Largest number is:"+y);
}
else
{
System.out.println("Largest number is:"+z);
}
}
}
Answer:
Given below is the program
Explanation:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the first number: ");
int num1 = scanner.nextInt();
System.out.print("Enter the second number: ");
int num2 = scanner.nextInt();
System.out.print("Enter the third number: ");
int num3 = scanner.nextInt();
int largest = num1;
if (num2 > largest) {
largest = num2;
}
if (num3 > largest) {
largest = num3;
}
System.out.println("The largest number is: " + largest);
}
}
Every line of code that runs in Java must be inside a class. In our example, we named the class Main. A class should always start with an uppercase first letter. The name of the java file must match the class name. When saving the file, save it using the class name and add ".java" to the end of the filename. To run the example above on your computer, make sure that Java is properly installed
See more:
https://brainly.in/question/2336496
#SPJ3