Integer arithmetic Flashcards

1
Q

What does the println() statement implicitly do with numeric variables in Java?
a) Treats them as strings
b) Adds them without conversion
c) Ignores them in the output
d) Converts them into binary format

A

a) Treats them as strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the correct output of System.out.println(intNumA + " + " + intNumB + " = " + intNumA + intNumB); if intNumA is 5 and intNumB is 3?
a) 5 + 3 = 53
b) 5 + 3 = 8
c) 5 + 3 = 15
d) 5 + 3 = 1

A

a) 5 + 3 = 53

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can we correct the output of System.out.println(intNumA + " + " + intNumB + " = " + intNumA + intNumB); to produce the correct sum of 8?
a) Add parentheses around intNumA + intNumB
b) Add a semicolon after intNumA
c) Use a separate println statement for intNumA and intNumB
d) Convert intNumA and intNumB to strings before addition

A

a) Add parentheses around intNumA + intNumB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In binary, how is the number 5 represented?
a) 101
b) 011
c) 110
d) 111

A

a) 101

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What will be the output of add(5, 3) in the add() method?
a) 8
b) 15
c) 5
d) 3

A

a) 8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is unit testing in software development?
a) Testing individual parts of an application
b) Testing the whole application only once
c) Testing only the main method
d) Testing only arithmetic operations

A

a) Testing individual parts of an application

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the assertEquals method in JUnit do?
a) Checks if two values are equal
b) Runs the code twice
c) Imports a JUnit package
d) Highlights syntax errors

A

a) Checks if two values are equal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In the add() method test, why does assertEquals(8, MathExamples.add(5,3)); pass?
a) Because add(5, 3) returns 8
b) Because add(5, 3) returns 10
c) Because add(5, 3) returns 5
d) Because add(5, 3) throws an error

A

a) Because add(5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the main purpose of including JUnit dependency in the Maven pom.xml file?
a) To allow unit testing with JUnit
b) To compile the code only
c) To handle arithmetic errors
d) To create classes automatically

A

a) To allow unit testing with JUnit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In Java, which symbol is used for multiplication?
a) *
b) x
c) X
d) ^

A

a) *

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the output of subtract(5, 3) if implemented correctly?
a) 2
b) 8
c) -2
d) 15

A

a) 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the division operator (/) return when dividing two integers in Java?
a) Only the whole number quotient
b) Both quotient and remainder
c) Only the remainder
d) The result in decimal form

A

a) Only the whole number quotient

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

If divide(8, 2) is called in a method, what result should be expected?
a) 4
b) 3
c) 8
d) 6

A

a) 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What will System.out.println(5 + " ÷ " + 3 + " = " + divide(5,3)); output, assuming divide(5, 3) is 1?
a) 5 ÷ 3 = 1
b) 5 ÷ 3 = 1.6667
c) 5 ÷ 3 = 2
d) 5 ÷ 3 = 8

A

a) 5 ÷ 3 = 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the modulo operator (%) return in Java?
a) The remainder of division
b) The quotient of division
c) The sum of numbers
d) The subtraction result

A

a) The remainder of division

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the output of modulo(5, 3) if correctly implemented?
a) 2
b) 1
c) 3
d) 5

A

a) 2

17
Q

What will MathExamples.exponent(5, 3) output if the exponent method is implemented correctly?
a) 125
b) 15
c) 8
d) 27

A

a) 125

18
Q

What library function does Java use for exponentiation, as there is no native operator?
a) Math.pow()
b) Math.exp()
c) Math.sqrt()
d) Math.pow2()

A

a) Math.pow()

19
Q

What is Test Driven Development (TDD)?
a) Writing tests before writing the method code
b) Testing code only after project completion
c) Writing code without any tests
d) Writing all tests in a single file

A

a) Writing tests before writing the method code

20
Q

What is the purpose of adding @Test before a method in JUnit?
a) To mark it as a JUnit test method
b) To create a new package
c) To throw an error in the code
d) To add extra assertions automatically

A

a) To mark it as a JUnit test method