Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program?

public class Program64
{
    void execute()
    {
        boolean underscoreOk = Character.isLetterOrDigit('_');
        boolean tabIsSpace = Character.isWhitespace('\t');
        System.out.println(underscoreOk + " " + tabIsSpace);
    }

    public static void main(String[] args)
    {
        Program64 demo = new Program64();
        demo.execute();
    }
}

  • A.The program prints false false
  • B.The program prints true false
  • C.The program prints true true
  • D.The program prints false true

Answer: D

An underscore is neither a letter nor a digit as far as Character is concerned, despite being legal in identifiers, so the first test is false. A tab is whitespace, so the second is true. Identifier rules and character classification are separate questions.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.