Test Data Types Java

257
18 июня 2017, 15:44

Доброго времени суток. Столкнулся в начале обучения с такой проблемой. Может кто объяснит чтобы не писать кучу лишнего кода (это как мне сказали) для тестирования базовых данных. Тут я показал как у меня только с int-ом а необходимо со всеми (byte, char, long, double, boolean).

public static void testInt() {
    int a = 256;
    int b = 46;
    int c = -8;
    int d = 152;
    int e;
    e = a + b;
    System.out.printf("\n%d + %d = %d", a, b, e);
    e = a + c;
    System.out.printf("\n%d + %d =%d", a, c, e);
    e = a + d;
    System.out.printf("\n%d + %d = %d", a, d, e);
    e = b + c;
    System.out.printf("\n%d + %d = %d", b, c, e);
    e = b + d;
    System.out.printf("\n%d + %d = %d", b, d, e);
    e = c + d;
    System.out.printf("\n%d + %d = %d", c, d, e);
    e = a - b;
    System.out.printf("\n%d - %d = %d", a, b, e);
    e = a - c;
    System.out.printf("\n%d - %d = %d", a, c, e);
    e = a - d;
    System.out.printf("\n%d - %d = %d", a, d, e);
    e = b - a;
    System.out.printf("\n%d - %d = %d", b, a, e);
    e = c - a;
    System.out.printf("\n%d - %d = %d", c, a, e);
    e = d - a;
    System.out.printf("\n%d - %d = %d", d, a, e);
    e = b - c;
    System.out.printf("\n%d - %d = %d", b, c, e);
    e = b - d;
    System.out.printf("\n%d - %d = %d", b, d, e);
    e = c - b;
    System.out.printf("\n%d - %d = %d", c, b, e);
    e = d - b;
    System.out.printf("\n%d - %d = %d", d, b, e);
    e = c - d;
    System.out.printf("\n%d - %d = %d", c, d, e);
    e = d - c;
    System.out.printf("\n%d - %d = %d", d, c, e);
    e = a * b;
    System.out.printf("\n%d * %d = %d", a, b, e);
    e = a * c;
    System.out.printf("\n%d * %d = %d", a, c, e);
    e = a * d;
    System.out.printf("\n%d * %d = %d", a, d, e);
    e = b * c;
    System.out.printf("\n%d * %d = %d", b, c, e);
    e = b * d;
    System.out.printf("\n%d * %d = %d", b, d, e);
    e = c * d;
    System.out.printf("\n%d * %d = %d", c, d, e);
    e = a / b;
    System.out.printf("\n%d / %d = %d", a, b, e);
    e = a / c;
    System.out.printf("\n%d / %d = %d", a, c, e);
    e = a / d;
    System.out.printf("\n%d / %d = %d", a, d, e);
    e = b / a;
    System.out.printf("\n%d / %d = %d", b, a, e);
    e = b / c;
    System.out.printf("\n%d / %d = %d", b, c, e);
    e = b / d;
    System.out.printf("\n%d / %d = %d", b, d, e);
    e = c / a;
    System.out.printf("\n%d / %d = %d", c, a, e);
    e = c / b;
    System.out.printf("\n%d / %d = %d", c, b, e);
    e = c / d;
    System.out.printf("\n%d / %d = %d", c, d, e);
    e = d / a;
    System.out.printf("\n%d / %d = %d", d, a, e);
    e = d / b;
    System.out.printf("\n%d / %d = %d", d, b, e);
    e = d / c;
    System.out.printf("\n%d / %d = %d", d, c, e);
    e = a % b;
    System.out.printf("\n%d %% %d = %d", a, b, e);
    e = a % c;
    System.out.printf("\n%d %% %d = %d", a, c, e);
    e = a % d;
    System.out.printf("\n%d %% %d = %d", a, d, e);
    e = b % a;
    System.out.printf("\n%d %% %d = %d", b, a, e);
    e = b % c;
    System.out.printf("\n%d %% %d = %d", b, c, e);
    e = b % d;
    System.out.printf("\n%d %% %d = %d", b, d, e);
    e = c % a;
    System.out.printf("\n%d %% %d = %d", c, a, e);
    e = c % b;
    System.out.printf("\n%d %% %d = %d", c, b, e);
    e = c % d;
    System.out.printf("\n%d %% %d = %d", c, d, e);
    e = d % a;
    System.out.printf("\n%d %% %d = %d", d, a, e);
    e = d % b;
    System.out.printf("\n%d  %d = %d", d, b, e);
    e = d % c;
    System.out.printf("\n%d %% %d = %d", d, c, e);
    e = -a;
    System.out.printf("\n-%d = %d", a, e);
    e = -b;
    System.out.printf("\n-%d = %d", b, e);
    e = -c;
    System.out.printf("\n-%d = %d", c, e);
    e = -d;
    System.out.printf("\n-%d = %d", d, e);
    e = +a;
    System.out.printf("\n+%d = %d", a, e);
    e = +b;
    System.out.printf("\n+%d = %d", b, e);
    e = +c;
    System.out.printf("\n+%d = %d", c, e);
    e = +d;
    System.out.printf("\n+%d = %d", d, e);
    e = ~a;
    System.out.printf("\n~%d = %d", a, e);
    e = ~b;
    System.out.printf("\n~%d = %d", b, e);
    e = ~c;
    System.out.printf("\n~%d = %d", c, e);
    e = ~d;
    System.out.printf("\n~%d = %d", d, e);
    e = a & b;
    System.out.printf("\n%d & %d = %d", a, b, e);
    e = a & c;
    System.out.printf("\n%d & %d = %d", a, c, e);
    e = a & d;
    System.out.printf("\n%d & %d = %d", a, d, e);
    e = b & a;
    System.out.printf("\n%d & %d = %d", b, a, e);
    e = b & c;
    System.out.printf("\n%d & %d = %d", b, c, e);
    e = b & d;
    System.out.printf("\n%d & %d = %d", b, d, e);
    e = c & a;
    System.out.printf("\n%d & %d = %d", c, a, e);
    e = c & b;
    System.out.printf("\n%d & %d = %d", c, b, e);
    e = c & d;
    System.out.printf("\n%d & %d = %d", c, d, e);
    e = d & a;
    System.out.printf("\n%d & %d = %d", d, a, e);
    e = d & b;
    System.out.printf("\n%d & %d = %d", d, b, e);
    e = d & c;
    System.out.printf("\n%d & %d = %d", d, c, e);
    e = a | b;
    System.out.printf("\n%d | %d = %d", a, b, e);
    e = a | c;
    System.out.printf("\n%d | %d = %d", a, c, e);
    e = a | d;
    System.out.printf("\n%d | %d = %d", a, d, e);
    e = b | a;
    System.out.printf("\n%d | %d = %d", b, a, e);
    e = b | c;
    System.out.printf("\n%d | %d = %d", b, c, e);
    e = b | d;
    System.out.printf("\n%d | %d = %d", b, d, e);
    e = c | a;
    System.out.printf("\n%d | %d = %d", c, a, e);
    e = c | b;
    System.out.printf("\n%d | %d = %d", c, b, e);
    e = c | d;
    System.out.printf("\n%d | %d = %d", c, d, e);
    e = d | a;
    System.out.printf("\n%d | %d = %d", d, a, e);
    e = d | b;
    System.out.printf("\n%d | %d = %d", d, b, e);
    e = d | c;
    System.out.printf("\n%d | %d = %d", d, c, e);
    e = a ^ b;
    System.out.printf("\n%d ^ %d = %d", a, b, e);
    e = a ^ c;
    System.out.printf("\n%d ^ %d = %d", a, c, e);
    e = a ^ d;
    System.out.printf("\n%d ^ %d = %d", a, d, e);
    e = b ^ a;
    System.out.printf("\n%d ^ %d = %d", b, a, e);
    e = b ^ c;
    System.out.printf("\n%d ^ %d = %d", b, c, e);
    e = b ^ d;
    System.out.printf("\n%d ^ %d = %d", b, d, e);
    e = c ^ a;
    System.out.printf("\n%d ^ %d = %d", c, a, e);
    e = c ^ b;
    System.out.printf("\n%d ^ %d = %d", c, b, e);
    e = c ^ d;
    System.out.printf("\n%d ^ %d = %d", c, d, e);
    e = d ^ a;
    System.out.printf("\n%d ^ %d = %d", d, a, e);
    e = d ^ b;
    System.out.printf("\n%d ^ %d = %d", d, b, e);
    e = d ^ c;
    System.out.printf("\n%d ^ %d = %d", d, c, e);
    e = a << 1;
    System.out.printf("\n%d << 1 = %d", a, e);
    e = b << 1;
    System.out.printf("\n%d << 1 = %d", b, e);
    e = c << 1;
    System.out.printf("\n%d << 1 = %d", c, e);
    e = d << 1;
    System.out.printf("\n%d << 1 = %d", d, e);
    e = a << -1;
    System.out.printf("\n%d << -1 = %d", a, e);
    e = b << -1;
    System.out.printf("\n%d << -1 = %d", b, e);
    e = c << -1;
    System.out.printf("\n%d << -1 = %d", c, e);
    e = d << -1;
    System.out.printf("\n%d << -1 = %d", d, e);
    /*e = a <<< 1;
    System.out.printf("\n%d <<< 1 = %d", a, e);
    e = b <<< 1;
    System.out.printf("\n%d <<< 1 = %d", b, e);
    e = c <<< 1;
    System.out.printf("\n%d <<< 1 = %d", c, e);
    e = d <<< 1;
    System.out.printf("\n%d <<< 1 = %d", d, e);
    e = a <<< -1;
    System.out.printf("\n%d <<< -1 = %d", a, e);
    e = b <<< -1;
    System.out.printf("\n%d <<< -1 = %d", b, e);
    e = c <<< -1;
    System.out.printf("\n%d <<< -1 = %d", c, e);
    e = d <<< -1;
    System.out.printf("\n%d <<< -1 = %d", d, e);*/
    e = a >> 1;
    System.out.printf("\n%d >> 1 = %d", a, e);
    e = b >> 1;
    System.out.printf("\n%d >> 1 = %d", b, e);
    e = c >> 1;
    System.out.printf("\n%d >> 1 = %d", c, e);
    e = d >> 1;
    System.out.printf("\n%d >> 1 = %d", d, e);
    e = a >> -1;
    System.out.printf("\n%d >> -1 = %d", a, e);
    e = b >> -1;
    System.out.printf("\n%d >> -1 = %d", b, e);
    e = c >> -1;
    System.out.printf("\n%d >> -1 = %d", c, e);
    e = d >> -1;
    System.out.printf("\n%d >> -1 = %d", d, e);
    /*e = a >>> 1;
    System.out.printf("\n%d >>> 1 = %d", a, e);
    e = b >>> 1;
    System.out.printf("\n%d >>> 1 = %d", b, e);
    e = c >>> 1;
    System.out.printf("\n%d >>> 1 = %d", c, e);
    e = d >>> 1;
    System.out.printf("\n%d >>> 1 = %d", d, e);
    e = a >>> -1;
    System.out.printf("\n%d >>> -1 = %d", a, e);
    e = b >>> -1;
    System.out.printf("\n%d >>> -1 = %d", b, e);
    e = c >>> -1;
    System.out.printf("\n%d >>> -1 = %d", c, e);
    e = d >>> -1;
    System.out.printf("\n%d >>> -1 = %d", d, e);
    Illegal start of type*/
}
Answer 1

Как минимум для начала нужно написать дополнительные методы, чтобы снизить дублирование кода. Также переменные можно сохранить в АrrayList и бегать по нему.

READ ALSO
вывод Яндекс карты - много городов

вывод Яндекс карты - много городов

Доброго дня, подсобите советом: на сайте много страниц с разными городами на каждой странице города нужно выводить карту с центрированием...

268
Вертикальное меню на уровне с header

Вертикальное меню на уровне с header

Уже долго ломаю голову, но никак не получается сделать так, чтоб вертикальное меню с лого были на уровне с хедером

333
Как сделать адаптивное меню, в котором бы не сразу все пункты исчезали, а в зависимости от ширины скрывались бы под кнопкой &ldquo;ещё&rdquo;? [требует правки]

Как сделать адаптивное меню, в котором бы не сразу все пункты исчезали, а в зависимости от ширины скрывались бы под кнопкой “ещё”? [требует правки]

Как сделать адаптивное меню, в котором бы не сразу все пункты исчезали, а в зависимости от ширины скрывались бы под кнопкой "ещё"?

223