KodeGym/Kursus Jawa/Sintaksis Jawa/Ngenalke ints lan Strings

Ngenalke ints lan Strings

kasedhiya

A snippet kuliah karo mentor minangka bagéan saka kursus Universitas Codegym. Ndaftar kanggo kursus lengkap.


"Halo, Amigo."

"Halo, Eleanor Carrey."

"Sebut wae aku Ellie. Ora perlu formal banget."

"Oke, Ellie."

"Aku yakin kanthi bantuanku, sampeyan bakal dadi salah siji sing paling apik. Aku duwe akeh pengalaman latihan wong anyar. Tetep karo aku, lan kabeh bakal apik. Ayo, ayo miwiti."

"Ana rong jinis utama ing Jawa : String lan int . Kita nyimpen strings/teks ing String, lan integers (nomer wutuh) ing int. Kanggo mratelakake variabel anyar, sampeyan kudu nemtokake jinis lan jeneng sawijining. Jeneng ora bisa dadi padha karo jeneng variabel lan/utawa fungsi liyane."

Tuladha 1, kode: Katrangan
String s;
Variabel anyar sdiumumake. Bisa nyimpen teks.
int i;
Variabel anyar i, diumumake. Bisa nyimpen integer.

"Sampeyan bisa nemtokake nilai kanggo variabel nalika sampeyan ngumumake."

Tuladha 2, kode: Katrangan
String s = "Ellie";
Variabel snyimpen string "Ellie".
int i = 5;
Variabel inyimpen nomer 5.

"Kanggo nemtokake nilai anyar kanggo variabel, kita nggunakake tandha =. Iki uga disebut 'operator penugasan' . Assignment tegese kanggo nyelehake menyang variabel nilai saka variabel liyane utawa siji diitung saka sawetara variabel. "

Tuladha 3, kode: Katrangan
int a = 5;
Variabel anyimpen nilai 5.
int b = 6;
Variabel bnyimpen nilai 6.
int c = a + b;
Variabel cnyimpen nilai 11.

"Nilai variabel bisa digunakake kanggo ngitung nilai anyar sing bakal ngganti sing lawas."

Tuladha 4, kode: Katrangan
int a = 2;
Saiki apadha karo 2
int b = 3;
Saiki bpadha karo 3
a = a + b;
Saiki apadha karo 5
b = b + 1;
Saiki bpadha karo 4

"Sampeyan bisa nggabungake string karo +tandha:"

Tuladha 5, kode: Katrangan
String s1 = "Rain";
String s2 = "In";
String s3 = s1 + s2 + "Spain";
Variabel s3nyimpen senar"RainInSpain"

"Kadhangkala, string sing dumadi saka siji utawa luwih spasi bisa migunani:"

Tuladha 6, kode: Katrangan
String s1 = "My favorite movie is";
String s2 = "Route";
int roadNumber = 66;
String text = s1 + " " + s2 + " " + roadNumber;
texttoko"My favorite movie is Route 66"

"Ayo deleng carane nampilake teks lan variabel ing layar:"

Ngenalake ints lan String - 1
Tuladha 7, kode:
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);

"Oalah, Diego njaluk aku menehi sawetara latihan:"

1
tugas
Java Syntax,  tingkatwulangan
Dikunci
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
tugas
1. modul,  tingkatwulangan
Dikunci
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
tugas
Java Syntax,  tingkatwulangan
Dikunci
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
tugas
Java Syntax,  tingkatwulangan
Dikunci
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.
1
tugas
Java Syntax,  tingkatwulangan
Dikunci
Comment out the superfluous
Comments are much more useful than they may seem at first glance! You can use them to hide your innermost thoughts from the compiler! Only your fellow programmers will be able to read them. Anyway, our program has some extra lines that prevent it from working as it should. Fix the problem by commenting out the superfluous lines.
1
tugas
Java Syntax,  tingkatwulangan
Dikunci
I'm 15 again!
You've got someone else's code in front of you. It's mysterious and incorrect. But programming power is concentrated in your hands. You can change everything, and the compiler will even help you with this task. What do you need to do to restore the delicate balance and peace? Just change the program so that the variable age takes the value 15.
1
tugas
Java Syntax,  tingkatwulangan
Dikunci
Only 20 will do
Many programmers are just crazy about brainteasers: Rubik's cubes, "use two matchsticks to get 100", the Tower of Hanoi, and others. Their brains are wired like that. Let's practice solving some brainteasers in programs. In this case, arrange the plus and minus signs so that the variable result is equal to 20.
Komentar
  • Popular
  • Anyar
  • lawas
Sampeyan kudu mlebu kanggo ninggalake komentar
Kaca iki durung duwe komentar