I am getting error of misplaced constructs & variableDeclarator expected in below code while calling the method “twosum” from main method. What am I missing here while calling?
public class Sumofint {
public int[] twoSum(int[] nums, int target) {
int total =0;
int output[] = null;
for(int i = 0; i<=nums.length-1; i++){
total = nums[i] +nums[i+1];
if (total == target){
output[0]= i;
output[1]=i+1;
}
}
return output;
}
public static void main(String []args) {
Sumofint obj = new Sumofint();
int arr[] = obj.twoSum({2,7,11,15},9);
System.out.println(arr[0]+", " + arr[1]);
}
}
I was expecting a normal call happening to the twoSum method