Un fragment de prelegere cu un mentor ca parte a cursului Universității Codegym. Înscrie-te la cursul complet.


— Bună, Amigo.

— Bună, Eleanor Carrey.

— Doar spune-mi Ellie. Nu e nevoie să fii atât de formal.

— Bine, Ellie.

"Cred că, cu ajutorul meu, vei fi în curând unul dintre cei mai buni. Am multă experiență în antrenamentul începătorilor. Rămâi cu mine și totul va fi bine. Ei bine, să începem."

„Există două tipuri majore în Java : String și int . Stocăm șiruri de caractere/text în String și numere întregi (numere întregi) în int. Pentru a declara o nouă variabilă, trebuie să specificați tipul și numele acesteia. Numele nu poate fi identice cu numele oricăror alte variabile și/sau funcții.”

Exemplul 1, cod: Descriere
String s;
sEste declarată o nouă variabilă . Poate stoca text.
int i;
Este declarată o nouă variabilă i. Poate stoca numere întregi.

„Puteți atribui valori variabilelor atunci când le declarați.”

Exemplul 2, cod: Descriere
String s = "Ellie";
Variabila sstochează șirul "Ellie".
int i = 5;
Variabila istochează numărul 5.

„Pentru a atribui o nouă valoare unei variabile, folosim semnul =. Se mai numește și „operator de atribuire” . Atribuirea înseamnă a plasa într-o variabilă o valoare dintr-o altă variabilă sau una calculată din mai multe variabile.

Exemplul 3, cod: Descriere
int a = 5;
Variabila astochează valoarea 5.
int b = 6;
Variabila bstochează valoarea 6.
int c = a + b;
Variabila cstochează valoarea 11.

„Valoarea unei variabile poate fi folosită pentru a calcula o nouă valoare care o va înlocui pe cea veche”.

Exemplul 4, cod: Descriere
int a = 2;
Acum aeste egal cu 2
int b = 3;
Acum beste egal cu 3
a = a + b;
Acum aeste egal cu 5
b = b + 1;
Acum beste egal cu 4

„Puteți îmbina șiruri cu +semnul:”

Exemplul 5, cod: Descriere
String s1 = "Rain";
String s2 = "In";
String s3 = s1 + s2 + "Spain";
Variable s3 stores the string "RainInSpain"

"Sometimes, strings consisting of one or more spaces can come in handy:"

Example 6, code: Description
String s1 = "My favorite movie is";
String s2 = "Route";
int roadNumber = 66;
String text = s1 + " " + s2 + " " + roadNumber;
text stores "My favorite movie is Route 66"

"Let's take a look at how we display text and variables on the screen:"

Introducerea intului și a șirurilor de caractere - 1
Example 7, code:
1
System.out.println("A man's gotta do what a man's gotta do");
2
String s = "A man's gotta do what a man's gotta do";
System.out.println(s);

"By the way, Diego asked me to give you a couple of exercises:"

1
Sarcină
Java Syntax,  nivellecţie
Blocat
CodeGym. Learn once - use anywhere
Here's a riddle: "Written once, it runs everywhere". Answer: A Java program. That's the right answer, because Java is logical and properly structured. Let's rephrase this slogan for students: "learn once, use anywhere!" Here's a little task on this topic: write a program that displays a useful phrase 10 times on the screen.
1
Sarcină
Modulul 1,  nivellecţie
Blocat
Uh... Happy New Year!
What if you don't abandon your studies? What if you keep on completing tasks and working through the lessons? If you do, then by next New Year's, which is at least three months away, you can celebrate the new year as a real programmer! That's the dream. But for now, let's go to work. Let's remove the unnecessary comments and display some New Year's well-wishes.
1
Sarcină
Java Syntax,  nivellecţie
Blocat
Let's change the code
Editing someone else's code is sometimes more difficult than writing your own. You can trust the experience of experts at the secret CodeGym center. That's why our curriculum includes tasks about fixing code. For now, let's open our textbook, wrap our brains around some simple code, and then change the code so that the variable name takes the value "Amigo".
1
Sarcină
Java Syntax,  nivellecţie
Blocat
A few more corrections
Articles such as "1001 Tips for Becoming a Great Programmer" almost always include a phrase like "Someone else's code will teach you how to write your own". A programmer seldom works alone, so this advice is the plain truth. You won't get anywhere by ignoring it. We have to get used to teamwork and fixing other people's code.