Starting Challenge
This is a basic challenge to test out the interface and your if
statement.
Challenge
A 2-sum is the sum of a list of numbers, but every number that's next to a 2
is counted twice. Given a list of numbers, print out their 2-sum.
For example, when given 1 2 3 4
as input, print 14
, the sum of the numbers with 1
and 3
counted twice.
Details
As mentioned here, the challenges provide Standard Input and you need to print your solution to the output (with System.out.println
) . You are provided with boilerplate code which processes the input and passes it to the method doStuff
.
In these contest challenges, you can run the code on "Test input" and see the results. To pass the challenge, you need to run the code on hidden "Contest Input", which will just return Correct or Incorrect.
Input
The first line will contain T, the number of test cases. Each test case contains 2 lines:
- N - the number of elements in a list.
- N numbers follow.
Output
Print out the 2-sum of each list on its own line.
Challenge
Find and print the 2-sum of each list.
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.
Comments
Stefan
May 26, 10:36 AM2 2 8 2 2 14 2 2 68 is 90 not 68
Learneroo
May 26, 10:38 AM@Stefan, 4+4+16+4+4+28+4+4 = 68. You don't double it again when it's next to another 2.