+ 1

What am I doing wrong in this simple code ? Why am I always getting the output as "false" ?

Problem:- Given a list of numbers and a number k, return whether any two numbers from the list add up to k. For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17. Here's my code :- https://code.sololearn.com/cb4g92XJ9k5d/?ref=app

29th Jan 2022, 10:12 AM
Smriti Kaur
Smriti Kaur - avatar
2 Respuestas
+ 4
you assign k to local variable, not to k as class field //int k = sc.nextInt(); k = sc.nextInt();
29th Jan 2022, 10:32 AM
zemiak
+ 2
zemiak o yeah true...🤦🏻‍♀️ and thanks for helping 👍
29th Jan 2022, 11:23 AM
Smriti Kaur
Smriti Kaur - avatar