Fixed narrowing cast from 'int' to 'Byte' / 'Short'

This commit is contained in:
Dmitry Cherniachenko
2017-06-23 22:37:37 +02:00
committed by Egor.Ushakov
parent 5db9ad29c8
commit aa78b7df28
7 changed files with 472 additions and 233 deletions

View File

@@ -12,47 +12,94 @@ public class TestPrimitives {
printDouble(1.23);
printChar('Z');
printBooleanBoxed(true);
printByteBoxed((byte) 123);
printShortBoxed((short) 257);
printIntBoxed(1);
printIntBoxed(40_000);
printLongBoxed(123L);
printFloatBoxed(1.23F);
printDoubleBoxed(1.23);
printCharBoxed('Z');
String.format("%b, %d, %d, %d, %c, %d", true, 1, 213, 40_000, 'c', 42L);
System.out.println(String.format("%b, %d, %d, %d", getBoolean(), getByte(), getShort(), getInt()));
System.out.printf("%b, %d, %d, %d, %c, %d", true, 1, 213, 40_000, 'c', 42L);
System.out.printf("%b, %d, %d, %d", getBoolean(), getByte(), getShort(), getInt());
new TestPrimitives(false, (byte) 123, (short) 257, 40_000, 123L, 3.14f, 1.618, 'A');
new TestPrimitives('A', 1.618, 3.14f, 123L, 40_000, (short) 257, (byte) 123, false);
}
private TestPrimitives(boolean bool, byte b, short s, int i, long l, float f, double d, char c) {
System.out.printf("%b, %d, %d, %d, %d, %.2f, %.2f, %c", bool, b, s, i, l, f, d, c);
}
private TestPrimitives(Character c, Double d, Float f, Long l, Integer i, Short s, Byte b, Boolean bool) {
System.out.printf("%b, %d, %d, %d, %d, %.2f, %.2f, %c", bool, b, s, i, l, f, d, c);
}
public void printBoolean(boolean b) {
System.out.println(String.format("%b", b));
System.out.printf("%b", b);
}
public void printByte(byte b) {
System.out.println(String.format("%d", b));
System.out.printf("%d", b);
}
public void printShort(short s) {
System.out.println(String.format("%d", s));
System.out.printf("%d", s);
}
public void printInt(int i) {
System.out.println(String.format("%d", i));
System.out.printf("%d", i);
}
public void printLong(long l) {
System.out.println(String.format("%d", l));
System.out.printf("%d", l);
}
public void printFloat(float f) {
System.out.println(String.format("%f", f));
System.out.printf("%f", f);
}
public void printDouble(double d) {
System.out.println(String.format("%f", d));
System.out.printf("%f", d);
}
public void printChar(char c) {
System.out.println(String.format("%c", c));
System.out.printf("%c", c);
}
public void printBooleanBoxed(Boolean b) {
System.out.printf("%b", b);
}
public void printByteBoxed(Byte b) {
System.out.printf("%d", b);
}
public void printShortBoxed(Short s) {
System.out.printf("%d", s);
}
public void printIntBoxed(Integer i) {
System.out.println(String.format("%d", i));
System.out.printf("%d", i);
}
public void printLongBoxed(Long l) {
System.out.printf("%d", l);
}
public void printFloatBoxed(Float f) {
System.out.printf("%f", f);
}
public void printDoubleBoxed(Double d) {
System.out.printf("%f", d);
}
public void printCharBoxed(Character c) {
System.out.printf("%c", c);
}