0% found this document useful (0 votes)
4 views3 pages

Java Program to Find Max of Four Numbers

The document outlines a Java experiment aimed at writing a function called MaxOfFour to determine the largest of four user-entered numbers. It explains the use of the Scanner class for input handling, the structure of the main method, and the implementation of conditional statements for comparison. The conclusion emphasizes the learning outcomes related to user input, conditional logic, and output formatting in Java.

Uploaded by

riyapataskar
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)
4 views3 pages

Java Program to Find Max of Four Numbers

The document outlines a Java experiment aimed at writing a function called MaxOfFour to determine the largest of four user-entered numbers. It explains the use of the Scanner class for input handling, the structure of the main method, and the implementation of conditional statements for comparison. The conclusion emphasizes the learning outcomes related to user input, conditional logic, and output formatting in Java.

Uploaded by

riyapataskar
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

JAVA EXPERIMENT 2

NAME:- RIYA PATASKAR


SE COMPS B
ROLL NO:- 45

AIM:- Write a function MaxOfFour to check the largest out of the four numbers
entered.

THEORY:-
 [Link]: The Scanner class from the [Link] package is used
to handle input, allowing the program to read data like integers and
strings from the keyboard.
 public: Declaring the main method as public makes it accessible to the
JVM for program execution.
 static: The main method is static, so it can be called directly by the
JVM without creating an instance of the class.
 void: The void keyword indicates that the main method does not
return any value.
 [Link]: Standard input stream used by the Scanner object to
receive user input from the keyboard.
 [Link]: A method to print data to the console, typically
used to display messages or results.
 Control Structures: The if-else statements are used to compare the four
numbers and update the largest value (max).
 Variables and Data Types: The four numbers are stored in int
variables, which are efficient for comparisons due to their fixed size.
 Comparison Logic: The program uses comparison operators (>) to
find the largest number through conditional checks.
 + Operator: The + operator concatenates strings and variables, used in
output statements for displaying results.
 Memory Allocation: The new keyword dynamically allocates memory
for objects like the Scanner during runtime.

CODE:-
OUTPUT:-
CONCLUSION:-
In this experiment, we implemented a Java program to find the largest of four
numbers entered by the user. We made use of the Scanner class to accept input
from the user and utilized conditional statements (if-else) to compare the values.
This experiment helped us strengthen our understanding of how to work with
user input, conditional logic, and output formatting in Java.

You might also like