JavaRush /Courses /New Java Syntax /Commands and code blocks

Commands and code blocks

New Java Syntax
Level 3, Lesson 6
Available

"Let me tell you about commands (statements) and code blocks. This is really simple stuff. A method body consists of commands, or statements. Each command ends in a semicolon."

Examples of commands:
1
String s = "Name";
2
System.out.println(1234);
3
return a + b * c;
4
throw new RuntimeException();
5
;

"A code block consists of several commands combined using curly brackets. A method body is a code block."

Examples:
1
{}
2
{
     throw new RuntimeException();
 }
3
{
     return null;
 }
4
{
     System.out.println(23);
     System.out.println(1);
     System.out.println(14);
 }

"The following rule is valid in almost any situation: wherever you can write one command, you can also write a code block. We will see examples of this in subsequent tasks."

Comments (1)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
30 November 2022
👍