Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class TwoNumbers {
- public static void main(String[] args) {
- int[] numArray = {4, 5, 7, 9, 3};
- int target = 12;
- }
- public int[] twoSum(int[] nums, int target) {
- for(int i=0; i<nums.length; i++) {
- if(nums[0] + nums[i] == target) {
- return nums[0, i];
- } else if(nums[1] + nums[i] == target) {
- return nums[1, i];
- } else if(nums[2] + nums[i] == target) {
- return nums[2, i];
- } else if(nums[3] + nums[i] == target) {
- return nums[3, i];
- } else if(nums[4] + nums[i] == target) {
- return nums[4, i];
- }
- i++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement