GOOGLE QUESTION
import java.util.ArrayList;
import java.util.Scanner;
class Google12{
public static void main(String arg[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter sum value");
int n=sc.nextInt();
System.out.println("Enter no of elements in array");
int m=sc.nextInt();
int arr1[]=new int[m];
ArrayList<Integer> aa=new ArrayList<Integer>();
for(int i=0;i<m;i++){
arr1[i]=sc.nextInt();
aa.add(arr1[i]);
}
int sum=0;
int count=0;
for(int i=0;i<aa.size()-1;i++){
sum=sum+aa.get(i)+aa.get(i+1);
if(sum==n){
count++;
System.out.println("No are :"+ aa.get(i) + aa.get(i+1));
}
else
{
sum=0;
}
}
if(count!=0){
System.out.println("Ok Pairs exist and are: "+count);
}
else
System.out.println("Pair dont exist");
}
}
Comments
Post a Comment