0
0
Rubyprogramming~5 mins

Arithmetic operators in Ruby - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the + operator do in Ruby?
The + operator adds two numbers together. For example, 2 + 3 equals 5.
Click to reveal answer
beginner
How do you perform division in Ruby and what is the result type?
Use the / operator to divide numbers. If both numbers are integers, Ruby returns an integer (floor division). To get a float result, use at least one float number, e.g., 5.0 / 2 returns 2.5.
Click to reveal answer
beginner
What is the difference between * and ** in Ruby?
* multiplies two numbers, while ** raises a number to the power of another. For example, 3 * 4 is 12, but 3 ** 4 is 81 (3 to the power of 4).
Click to reveal answer
beginner
What does the % operator do in Ruby?
The % operator gives the remainder of division between two numbers. For example, 7 % 3 equals 1 because 7 divided by 3 leaves a remainder of 1.
Click to reveal answer
intermediate
How can you combine arithmetic operators in Ruby?
You can combine operators like +, -, *, /, and % in expressions. Ruby follows standard math order: parentheses first, then exponentiation, multiplication/division/modulus, and finally addition/subtraction.
Click to reveal answer
What is the result of 10 / 4 in Ruby if both are integers?
A3
B2.5
C4
D2
Which operator raises a number to a power in Ruby?
A**
B*
C+
D%
What does 15 % 4 return?
A1
B3
C11
D4
Which operator has the highest precedence in Ruby arithmetic?
A**
B*
C+
D-
What is the result of 2 + 3 * 4 in Ruby?
A20
B24
C14
D10
Explain how Ruby handles division between two integers and how to get a decimal result.
Think about how dividing 5 by 2 behaves differently with integers and floats.
You got /3 concepts.
    Describe the order of operations for arithmetic operators in Ruby.
    Remember the math rule PEMDAS but adapted for Ruby operators.
    You got /4 concepts.