0% found this document useful (0 votes)
10 views2 pages

Program 3

This Java program takes 3 integer numbers as input from the user, compares them using conditional statements, and prints out the largest of the 3 numbers. It uses a Scanner to take input, compares the numbers by assigning them to temporary variables, and outputs the largest number.

Uploaded by

Velly Creation
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Program 3

This Java program takes 3 integer numbers as input from the user, compares them using conditional statements, and prints out the largest of the 3 numbers. It uses a Scanner to take input, compares the numbers by assigning them to temporary variables, and outputs the largest number.

Uploaded by

Velly Creation
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program 3.

Write a Java Program to Find the Largest


Among Three Numbers.

import java.util.Scanner;
public class LargestNumber
{
public static void main(String[] args)
{
int a, b, c, largest, temp;
//object of the Scanner class
Scanner sc = new Scanner(System.in);
//reading input from the user
System.out.println("Enter the first number:");
a = sc.nextInt();
System.out.println("Enter the second number:");
b = sc.nextInt();
System.out.println("Enter the third number:");
c = sc.nextInt();
//comparing a and b and storing the largest number in a temp
variable
temp=a>b?a:b;
//comparing the temp variable with c and storing the result in the
variable
largest=c>temp?c:temp;
//prints the largest number
System.out.println("The largest number is: "+largest);
}
}

Output.

You might also like