Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Stop logger to print from new line

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading