A Java implementation of the Two Sum problem using arrays and a nested-loop approach.
Given an array of integers and a target value, find pairs of elements whose sum is equal to the target.
This program uses a Brute Force approach:
- Take the size of the array as input.
- Take array elements from the user.
- Take the target value.
- Compare every possible pair of elements.
- If the sum of a pair equals the target, display the pair.
- If no pair is found, display a message.
- Java
- Arrays
- Loops
- Scanner
- Basic Problem Solving
- Time Complexity: O(n²)
- Space Complexity: O(n)
-
Make sure Java is installed.
-
Clone this repository.
-
Compile the program:
javac Two_sum.java#
4.Run the program: java Two_sum
This project helped me practice:
- Arrays
- Nested loops
- User input
- Conditional statements
- Brute Force problem solving
- Time and space complexity
Nikhil
BCA Student | Java & Software Development Learner