KEMBAR78
Hir Dey Java | PDF
0% found this document useful (0 votes)
5 views2 pages

Hir Dey Java

Uploaded by

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

Hir Dey Java

Uploaded by

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

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

ASSESSMENT 1
Student Name: Hirdeypreet Singh UID: 23BCS13178
Branch: BE CSE Section/Group: 709-A
Semester: IV Date of Performance:29/01/25
Subject Name: OOP using JAVA Subject Code: 23CSP-202

1. Aim:
In a company, the HR department wants to analyse the salaries of
employees. They need to find the highest salary, the lowest salary, and the
total salary of all employees. Help the HR department by writing a program
that takes the list of employee salaries as input and calculates these values.

2. JAVA Code:

import java.util.Scanner;

public class SalaryAnalysis {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of employees: ");
int n = scanner.nextInt();
int[] salaries = new int[n];
System.out.println("Enter the salaries:");
for (int i = 0; i < n; i++) {
salaries[i] = scanner.nextInt();
}
int maxSalary = salaries[0];
int minSalary = salaries[0];
int totalSalary = 0;
for (int salary : salaries) {
if (salary > maxSalary) {
maxSalary = salary;
}
if (salary < minSalary) {
minSalary = salary;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

totalSalary += salary;
}
System.out.println("Highest Salary: " + maxSalary);
System.out.println("Lowest Salary: " + minSalary);
System.out.println("Total Salary: " + totalSalary);
scanner.close();
}
}

3. Output:

4. Learning Outcomes:
· Understanding Arrays – Storing and processing multiple
employee salaries efficiently.

· Implementing Looping Constructs – Using for loops to


traverse the salary list and perform calculations.

· Applying Conditional Statements – Identifying the highest


and lowest salaries through comparisons.

· Using Mathematical Operations – Computing total salary by


iterating through salary values.

You might also like