Integer arithmetic Flashcards
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) Treats them as strings
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) 5 + 3 = 53
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) Add parentheses around intNumA + intNumB
In binary, how is the number 5 represented?
a) 101
b) 011
c) 110
d) 111
a) 101
What will be the output of add(5, 3)
in the add() method?
a) 8
b) 15
c) 5
d) 3
a) 8
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) Testing individual parts of an application
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) Checks if two values are equal
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) Because add(5
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) To allow unit testing with JUnit
In Java, which symbol is used for multiplication?
a) *
b) x
c) X
d) ^
a) *
What is the output of subtract(5, 3)
if implemented correctly?
a) 2
b) 8
c) -2
d) 15
a) 2
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) Only the whole number quotient
If divide(8, 2)
is called in a method, what result should be expected?
a) 4
b) 3
c) 8
d) 6
a) 4
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) 5 ÷ 3 = 1
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) The remainder of division