Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DecimalToBinary {
- public static StringBuilder decimalToBinary(int number) {
- int num = 11;
- StringBuilder result = new StringBuilder();
- int i = 0;
- while (number > 0) {
- int remainder = number % 2;
- result.append(String.valueOf(remainder));
- number = number / 2;
- i++;
- }
- return result.reverse();
- }
- }
- import org.junit.Assert;
- import org.junit.Test;
- import static org.junit.Assert.*;
- public class DecimalToBinaryTest {
- @Test // adnotacja
- public void shouldDecimalToBinary() {
- // given
- int number = 11;
- // when
- StringBuilder result = DecimalToBinary.decimalToBinary(number);
- // then
- Assert.assertEquals(1011, result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement