Print a boolean value with printf

I assume you are running into a buffering issue, such that your program exits before your buffer flushes. When you use printf() or print() it doesn’t necessarily flush without a newline. You can use an explicit flush() boolean car = true; System.out.printf(“%b”,car); System.out.flush(); or add a new-line (which will also cause a flush()) boolean car = true; System.out.printf(“%b%n”,car); See also Buffered Streams … Read more

calling boolean method, heads or tails

You should call like : public class Abc { public static void main(String[] args) { System.out.println(headsOrTails()); } public static boolean headsOrTails() { boolean coinState; if (Math.random() < 0.5) {//heads 50% of the time coinState = true; //heads } else { coinState = false; //tails } return coinState; } } and it will print the output … Read more