sum of consecutive integer is equal to target is index

sum of consecutive integer is equal to target is index
SOURCE : IndexPrintArray.java




public class IndexPrintArray {

public void twoSum(int[] numbers, int target) {

int sum=0;
int [] m = new int[numbers.length];
for(int i =0;i
m[i]=numbers[i];
}
int [] twoindex=new int[2];

for(int i =0;i
sum=0;
sum+=m[i];
if((sum+m[i+1])!=target){
continue;

}else{

twoindex[0]=i+1;
twoindex[1]=i+2;
System.out.println("sum of consecutive integer is equall to target is index "+ " " +twoindex[0] +" "+ "to ");
System.out.println("index"+ " " +twoindex[1]);
break;

}


}


}



public static void main(String[] args) {

int[] numbers = {23,65,6,3,8,7};
int target=9;

IndexPrintArray in = new IndexPrintArray();
in.twoSum(numbers,target);
// System.out.println(twoindex[0]);



}

}



INPUT

int[] numbers = {23,65,6,3,8,7}
int target=9



OUTPUT

sum of consecutive integer is equal to target is index 3 to index 4








Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment