This assignment is due on Wednesday 1:10pm
In this lab, you will build interactive console applications by implementing two fundamental array algorithms discussed in class:
- Find Maximum Value
- Pair Sum (Brute Force Search)
Unlike previous examples where arrays and target values were hardcoded, this assignment requires your programs to collect all necessary input from the user using Java's Scanner class.
The goal is to strengthen your understanding of:
- User input handling
- Arrays
- Loops
- Brute-force searching
- Time complexity
- Writing clean, readable Java code
Write a Java program that finds the largest value in an array and its index.
Your program must:
-
Prompt the user to enter the number of elements in the array.
-
Create an integer array of that size.
-
Prompt the user to enter each array element one at a time.
-
Search through the array to determine:
- The maximum value
- The index where the maximum value occurs
-
Display the results in a clear and professional format.
Write a Java program that searches for a unique pair of numbers whose sum equals a target value.
Your program must:
-
Prompt the user for the array size.
-
Accept each array element from the user.
-
Prompt the user to enter a Target Sum.
-
Use the Brute Force (Nested Loop) algorithm to search for a matching pair.
-
If a pair is found, display:
- Both indices
- Their values
- The equation
-
If no pair exists, print an appropriate message.
Your project should contain the following Java files:
Lab2/
│
├── FindMax.java
├── PairSum.java
└── README.md
Follow the Git workflow below exactly.
Fork the official repository:
https://github.com/DCIT204-2026/DCIT204_LABS-2.git
git clone <YOUR_FORK_URL>Create a new branch using the format:
firstName_StudentId
Example:
git checkout -b john_10912345Branch Naming Format
firstname_studentID
Examples
joseph_11023456
mary_10987654
john_10876543
Implement both Java programs.
git add .
git commit -m "Completed Lab 2 Array Algorithms"git push origin firstName_StudentIdExample:
git push origin john_10912345After completing this lab, you should be able to:
- Work confidently with arrays.
- Accept user input using
Scanner. - Implement a linear search algorithm.
- Implement a brute-force pair search.
- Analyze algorithm time complexity.
- Write clean, maintainable Java code.
- Use Git and GitHub for version control.
Take your time, write clean code, test your programs thoroughly, and remember:
Correctness first, then readability, then efficiency.