+ 3

Where we use curly braces and where we use colon in java.

15th Jun 2018, 12:15 PM
Maninder $ingh
Maninder $ingh - avatar
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"); } }
15th Jun 2018, 12:24 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 8
Maninder Singh In my opinion, by using curly braces in if-else statements, it will increase code readability😉.
15th Jun 2018, 12:29 PM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 4
colon is used in switch case:
15th Jun 2018, 5:54 PM
Nitish kumar jha
Nitish kumar jha - avatar
+ 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.
16th Jun 2018, 4:34 AM
Rusty.Metal
+ 2
Muhd Khairul Amirin Bin Yaacob why we use curly braces in if else because it works without curly braces.
15th Jun 2018, 12:27 PM
Maninder $ingh
Maninder $ingh - avatar
+ 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
16th Jun 2018, 7:36 AM
Dlite
Dlite - avatar