Home Why does this code using random strings print "hello world"?
Reply: 0

Why does this code using random strings print "hello world"?

user575
1#
user575 Published in June 20, 2018, 10:54 pm

The following print statement would print "hello world". Could anyone explain this?

System.out.println(randomString(-229985452) + " " + randomString(-147909649));

And randomString() looks like this:

public static String randomString(int i)
{
    Random ran = new Random(i);
    StringBuilder sb = new StringBuilder();
    while (true)
    {
        int k = ran.nextInt(27);
        if (k == 0)
            break;

        sb.append((char)('`' + k));
    }

    return sb.toString();
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.715409 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO