Question

I have this piece of code that generates a random characters (ASCII)

public char getRandChar(){ return (char)rand.nextInt(27); }

and then I'll print it out using this

System.out.println(new Character(getRandChar()));

How but apparently it is returning a blank value

Was it helpful?

Solution

This is because rand.nextInt(27); is returning unprintable character codes. This will be evident if you change your code to return (char)65; for example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top