+ 1

Indentation in java

Is indentation compulsory in java. As i am learning the if statement in java , I found that whether there is an indent or not, in the else statement the program works fine.

20th Jun 2021, 4:40 PM
kushal
3 Respuestas
+ 3
No indentation is not nessesary, it's just there to make the code look more better and easily understandable.
20th Jun 2021, 4:46 PM
Eashan Morajkar
Eashan Morajkar - avatar
+ 1
Java uses a blocks making by { } curly braces. There is no need Indentation .but adding Indentation will make code more readable..
20th Jun 2021, 5:48 PM
Jayakrishna 🇮🇳
0
Not compulsory. But it looks good when you use indentation. 1. public void method() { if(condition) { System.out.print("if"); } else{ System.out.print("else"); } } 2. public void method() { if (condition) { System.out.print("if"); } else { System.out.print("else"); } } Which looks better?
21st Jun 2021, 3:52 PM
Java Developer
Java Developer - avatar