-3

(12193170: not the same question (or not the right answers for that matter...))

So basically why this:

public class HelloWorld {
public static void main(String[] args) {
    System.out.println("Hello World");
    } 
}

And not this:

public class HelloWorld 
{public static void main(String[] args) 
{System.out.println("Hello World");}}`
Emdosis
  • 1
  • 7
  • 1
    What if there's more than one statement? And this will at best be opinion based. – Carcigenicate Oct 11 '18 at 11:58
  • 1
    Your code will be completly unreadable if there if there where a couple if-statements inside (at least for other people then Emdosis). – Mike Oct 12 '18 at 10:27

1 Answers1

2

The main reason for using a particular formatting ( position braces and indentation) is for visibility.

Your example is too simple and you could argue that both versions are easy to read (although first version look simpler to me). When you have hundreds of lines of code, you really appreciate having your code properly formatted.

But you could use other formatting styles if you prefer, for example:

public class HelloWorld 
{
   public static void main(String[] args) 
   {
     System.out.println("Hello World");
   } 
}
Daniel GL
  • 1,081
  • 9
  • 21