Digits of a number
Consider the last digit of a number method that we encountered in the previous lesson. This method uses % 10 to grab
the last digit of an integer.
Write a PASSING test that illustrates that this method works for a given integer value.
The necessary JUnit packages have been imported for you.
Diese Übung ist Teil des Kurses
Introduction to Testing in Java
Anleitung zur Übung
- Enter the correct annotation that will enable JUnit to execute this test.
- Enter the expected last digit of the provided integer.
- Use the correct JUnit assertion to assert equality between the expected and actual values.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
public class LastDigitWithTests {
public static void main(String[] args) {
launchTestsAndPrint(LastDigitTest.class);
}
}
class LastDigitTest {
// Use the correct annotation to mark this as a JUnit test
@____
void testLastDigit() {
int number = 2025;
// What is the expected output?
int expected = ____;
int actual = LastDigit.lastDigit(number);
// Use the correct JUnit assertion for the scenario
____(expected, actual);
}
}