JavaRush/Courses/New Java Syntax/Ready for the first program

Ready for the first program

Open

(an hour later)

"Terrific! Where did we stop?"

"The code inside a method or something like that."

"Right. Exactly. The body of a method consists of commands. We could even say that a method is a group of commands that has been given a name (method name). Both statements would be true."

"There are all sorts of commands. Are there dogs on your planet?"

"Only domesticated robotic wolves."

"Do they execute commands?"

"Yep. 'Bite', 'Eat', 'Tear', and 'Good! Heel!'"

Ready for the first program - 1

"Hmm. Nice commands! But there aren't very many of them."

"How many do we need?"

"The Java language has commands for every occasion. Each command describes some action. At the end of each command, we use a semicolon."

"Here are some examples of commands:"

Command Description (what it does)
System.out.println(1);
Displays the number 1 on the screen
System.out.println("Amigo");
Displays "Amigo" on the screen
System.out.println("Rishi & Amigo");
Displays "Rishi & Amigo" on the screen

"Actually, this is just one command System.out.println. We use parentheses to pass arguments to the command. Depending on the value of the arguments, the same command can execute different actions."

"That's very convenient."

"Yes. If you want to display some text on the screen, you put double quotes on each side of it.

A single quotation mark looks like this: '. A double quotation mark looks like this: ". A double quotation mark is not the same thing as two single quotation marks. Please don't confuse them."

"The key for the double quotation mark is next to the Enter button on the keyboard, right?"

"Right."

Amigo’s pulse accelerated from 3 to 5 GHz. He still couldn’t believe it. He had just learned how to print strings on the screen, and it turned out to be much easier that he had expected.
Amigo looked out the window to distract himself from his thoughts and calm down. The leaves were turning yellow. The Rusty Season is very close, he noted automatically. An illuminator let him see much further than usual. The newcomers’ technology was very advanced indeed. But did he care about the leaves now? He would multiply his knowledge again by evening!

Ready for the first program - 2

But his thoughts wouldn’t calm down. One day, he’d write a program to make all robots take refuge in their homes during the Rusty Season. That program alone would save thousands of robo-lives…

"This command has two versions: System.out.println() and System.out.print()"

"If you use the System.out.println() command a few times, you’ll see that each time the text you pass to the command is displayed on a separate line. If you use the System.out.print() command, the text is displayed on the same line. For example:"

Commands What will be displayed on the screen
1
System.out.println("Amigo");
 System.out.println("Is The");
 System.out.println("Best");
Amigo
Is The
Best
2
System.out.print("Amigo");
 System.out.println("Is The");
 System.out.print("Best");
AmigoIs The
Best
3
System.out.print("Amigo");
 System.out.print("Is The");
 System.out.print("Best");
AmigoIs TheBest

"Keep this in mind: println doesn't start printing text from a new line. It prints text on the current line, but makes it so the next text will be printed on a new line."

"The println() command prints the text on the screen and adds a special unseen 'newline character'. This is what makes the next text start on a new line."

"What does the entire program look like?"

"Look at the screen:"

public class Home
 {
     public static void main(String[] args)
     {
         System.out.print("Amigo ");
         System.out.print("Is The ");
         System.out.print("Best");
     }
 }

"Oh! It's all clear. We added spaces to the ends of the words so they wouldn’t all run together, right?"

"Exactly. You’re a smart little guy."

The comment made Amigo radiate with pride.

"Great. Here’s another task for you.."

1
Task
New Java Syntax,  1 level,  3 lecture
Locked
It's cool to be a programmer!
It's cool to be a programmer!
Комментарии (8)
  • популярные
  • новые
  • старые
Для того, чтобы оставить комментарий Вы должны sign in
Muhammadyor Avazbekov Backend Developer
18 December 2024, 15:15
Good lesson.
Toavina
Уровень 1
16 November 2023, 02:58
Tys
13 November 2023, 17:30
characteristics a prople list variant but funny every days need all humense . game ect . won a beat . using tools monters infinite game box . personally and nirvanas skill . chipmunk93 . yoa @unity canada java.apps
13 November 2023, 17:29
bro jim canada arcade game exiler tools 50 £ okey deal . i am using chips ugradre loading lates
Anonymous #3311186
Уровень 1
30 May 2023, 08:43
I think after several attempts and analyze I understand how commands function
Miran Haydarov
Уровень 2
6 April 2022, 14:23
I could do it
Anonymous #3038939
Уровень 12
27 March 2022, 18:59
Nice
Shekerbek_Zholdoshev
Уровень 3
14 March 2022, 12:21
good job