I’m new to java, trying to use logger instead of System.out.print();
Making cows and bulls game and can’t figure out how to make logger printing each digit from new line and instead print it as one number.
Example :
logger.info(player + ", you lose. The number is : ");
for (int i = 0; i < random.length; i++) {
logger.info("{}", random[i]);
}
}
output is :
17:54:27.668 [main] INFO com.bullsandcow.GameScreen - Viktors, you lose. The number is :
17:54:27.668 [main] INFO com.bullsandcow.GameScreen - 3
17:54:27.673 [main] INFO com.bullsandcow.GameScreen - 6
17:54:27.673 [main] INFO com.bullsandcow.GameScreen - 4
17:54:27.673 [main] INFO com.bullsandcow.GameScreen - 7
What I want is to print 3647 as one number.
>Solution :
i’m not sure what you want, but if you just need the random number in the same line, you can try:
String s = "";
for (int i = 0; i < random.length; i++) {
s += random[i];
}
logger.info("{}", s);