• Martin Thoma
  • Home
  • Categories
  • Tags
  • Archives
  • Support me

Java Puzzle #12: Control-flow

Contents

  • Answer
  • Explanation

What is the output of the following HelloWorld.java?

public class HelloWorld {
    public static void main(String[] args) {
        if (2 < 1); {
            System.out.println("Yes");
        }
    }
}

. . . . . . . . . . .

Answer

The output is "Yes".

Explanation

The ; means, that no block is executed. The { ... } is just a code block and not really related to the if-statement.

Published

Okt 17, 2012
by Martin Thoma

Category

Code

Tags

  • Java 36
  • Programming 52
  • puzzle 22

Contact

  • Martin Thoma - A blog about Code, the Web and Cyberculture
  • E-mail subscription
  • RSS-Feed
  • Privacy/Datenschutzerklärung
  • Impressum
  • Powered by Pelican. Theme: Elegant by Talha Mansoor