+ 3
Where we use curly braces and where we use colon in java.
6 ответов
+ 6
1. Semicolon (;) is used to end a statement.
System.out.print("java") ;
2. Curly braces ( } ) is used after declaring a method or class.
class Sololearn {
public void code(){
System.out.print("hi");
}
}
+ 8
Maninder Singh In my opinion, by using curly braces in if-else statements, it will increase code readability😉.
+ 4
colon is used in switch case:
+ 3
Maninder Singh if there's only 1 statement inside an if or else or whatever, it's not necessary to use curly braces. If there are multiple statements you need to use them.
+ 2
Muhd Khairul Amirin Bin Yaacob why we use curly braces in if else because it works without curly braces.
+ 2
You can write 1000 lines of code in Java on a single line since Java is a free form language , provided they are terminated by semicolons (;)
As for curly braces {}
They are mainly used for Defining methods and class declarations