You are on page 1of 2

Operators

1. Find whether agiven number is odd/even without using % or / operator


2. Given 2 ints, a and b, return true if one if them is 10 or if their sum is 10.

makes10(9, 10) ? true


makes10(9, 9) ? false
makes10(1, 9) ? true

3. We'll say that a number is "teen" if it is in the range 13..19 inclusive. Given 3 int
values, return true if 1 or more of them are teen.

hasTeen(13, 20, 10) ? true


hasTeen(20, 19, 10) ? true
hasTeen(20, 10, 13) ? true

4. Given two non-negative int values, return true if they have the same last digit,
such as with 27 and 57.

lastDigit(7, 17) ? true


lastDigit(6, 17) ? false
lastDigit(3, 113) ? true

5. Given two int values, return their sum. Unless the two values are the same, then
return double their sum.

sumDouble(1, 2) ? 3
sumDouble(3, 2) ? 5
sumDouble(2, 2) ? 8

6. You're given three integers, a, b and c. It is guaranteed that two of these integers
are equal to each other. What is the value of the third integer?
Example
For a = 2, b = 7 and c = 2, the output should be
extraNumber(a, b, c) = 7.
The two equal numbers are a and c. The third number (b) equals 7, which is the
answer.
7. Once Mary heard a famous song, and a line from it stuck in her head. That line
was "Will you still love me when I'm no longer young and beautiful?". Mary
believes that a person is loved if and only if he/she is both young and beautiful, but
this is quite a depressing thought, so she wants to put her belief to the test.
Knowing whether a person is young, beautiful and loved, find out if they contradict
Mary's belief.
A person contradicts Mary's belief if one of the following statements is true:
they are young and beautiful but not loved;
they are loved but not young or not beautiful.
Example
For young = true, beautiful = true and loved = true, the output should be
willYou(young, beautiful, loved) = false.
Young and beautiful people are loved according to Mary's belief.
For young = true, beautiful = false and loved = true, the output should be
willYou(young, beautiful, loved) = true.

8. Given an integer, , perform the following conditional actions:

If is odd, print Weird


If is even and in the inclusive range of 2 to 5 , print Not Weird
If is even and in the inclusive range of 6 to 20 , print Weird
If is even and greater than 20 , print Not Weird

You might also like