-1
Scanner in =new Scanner(System.in);    
int x=in.nextInt();    
Queue<Integer> a=new ArrayDeque<Integer>();
Queue<Integer> b=new ArrayDeque<Integer>();

for(int a_i=0; a_i < n; a_i++){
    a.offer(in.nextInt());
}
for(int b_i=0; b_i < m; b_i++){
    b.offer(in.nextInt());
}  

int temp=0,ans=0;
while(temp<x && !a.empty() && !b.empty()){ 
    temp+=a.peek()<b.peek()?a.poll():b.poll();
    ans++;             
}

when i run this Solution.java:26: error: cannot find symbol while(temp

Venkat Vinay
  • 89
  • 2
  • 5
  • 2
    What is `x` that temp is being compared against in the while loop? – Tom O. Sep 27 '17 at 14:28
  • Post the complete code so that we can help. where is `x` declared? – Sridhar Sep 27 '17 at 14:29
  • I declared 'x' as int at the top of my code. It seems the problem rose because of the empty() method I used for the Queue. After I changed it to isEmpty() my code worked. Btw thanks for replying. – Venkat Vinay Sep 28 '17 at 05:05

1 Answers1

0

Your variable x is not declared anywhere that I can see. I would imagine this is your problem. You need to declare x with a data type and give it an initial value before you compare against it.

Tom O.
  • 5,730
  • 2
  • 21
  • 35