Jump to content

My friend needs help on this java thing

cmb6062
 Given 2 ints, a and b, return their sum. However, sums in the range 10..19 inclusive, are forbidden, so in that case just return 20.

 

sortaSum(3, 4) → 7

sortaSum(9, 4) → 20

sortaSum(10, 11) → 21

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

 

 Given 2 ints, a and b, return their sum. However, sums in the range 10..19 inclusive, are forbidden, so in that case just return 20.
 
sortaSum(3, 4) → 7
sortaSum(9, 4) → 20
sortaSum(10, 11) → 21

 

 

Is there any particular reason why the results cannot return 10, 11, 12, 13, 14... 19?

Just put in a condition that if the sum is greater than equal to 10 AND less than equal to 19, return 20.

Guide: DSLR or Video camera?, Guide: Film/Photo makers' useful resources, Guide: Lenses, a quick primer

Nikon D4, Nikon D800E, Fuji X-E2, Canon G16, Gopro Hero 3+, iPhone 5s. Hasselblad 500C/M, Sony PXW-FS7

ICT Consultant, Photographer, Video producer, Scuba diver and underwater explorer, Nature & humanitarian documentary producer

Link to comment
Share on other sites

Link to post
Share on other sites

What's the issue? Get the sum, check if it's in the forbidden range, and return the appropriate value.

Link to comment
Share on other sites

Link to post
Share on other sites

just add the values, and at the end put an if statement checking if its in the forbidden range, if thats the case, just return 20.

Link to comment
Share on other sites

Link to post
Share on other sites

just add the values, and at the end put an if statement checking if its in the forbidden range, if thats the case, just return 20.

 

What's the issue? Get the sum, check if it's in the forbidden range, and return the appropriate value.

 

Is there any particular reason why the results cannot return 10, 11, 12, 13, 14... 19?

Just put in a condition that if the sum is greater than equal to 10 AND less than equal to 19, return 20.

I think it worked for her xD, thank you guys for the answers

Link to comment
Share on other sites

Link to post
Share on other sites


int f(int a , int b)

{

int s = a + b;

if( s >= 10 && s <=19) return 20;

return s;

}

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Why don't 'she' ask for help 'herself'? Or is this just another manifestation of 'her' level of effort?

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Why don't 'she' ask for help 'herself'? Or is this just another manifestation of 'her' level of effort?

She had been struggling for a while, then asked me, i didnt know anything about coding. So i just asked for help here and sent her the link. and that managed to help her solve the problem.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×