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


"Aku arep menehi pitutur marang kowe babagan mbandhingake variabel ing Jawa. "

"Sampeyan wis ngerti operator perbandingan sing paling gampang - kurang saka (<) lan luwih gedhe tinimbang (>)."

"Ya wis."

"Ana uga operator sing padha karo (==) lan ora padha karo (!=). Uga, kurang saka utawa padha karo (<=) lan luwih saka utawa padha karo (>=)."

"Saiki iki dadi menarik."

"Elinga yen ora ana operator == utawa => ing Jawa!"

" Tandha = digunakake kanggo operasi penugasan. Pramila rong pratandha sing padha (==) digunakake kanggo nyoba kesetaraan. Kanggo mriksa manawa variabel ora padha , gunakake operator != ."

"Aku weruh."

"Nalika mbandhingake rong variabel ing Jawa nggunakake operator ==, kita mbandhingake isi variabel."

"Mangkono, kanggo variabel primitif , nilai kasebut dibandhingake ."

"Kanggo variabel referensi , referensi dibandhingake . Upamane kita duwe obyek sing padha nanging beda. Amarga referensi kasebut beda , perbandingan bakal nuduhake yen ora padha, yaiku asil perbandingan bakal salah . mung yen loro referensi nuduhake obyek sing padha. "

"Kanggo mbandhingake isi internal obyek, kita nggunakake cara khusus witjaksono . Cara iki (lan kabeh cara saka kelas Obyek) ditambahake menyang kelas dening compiler sanajan sampeyan ora ngumumake. Ayo kula nuduhake sawetara conto: "

Kode Panjelasan
1
int a = 5;
int b = 5;
System.out.println(a == b);
Bandingake jinis primitif .
bener bakal ditampilake ing layar.
2
Cat cat1 = new Cat("Oscar");
Cat cat2 = cat1;
System.out.println(cat1 == cat2);
Bandingake referensi .
bener bakal ditampilake ing layar.
Loro-lorone variabel nyimpen referensi menyang obyek sing padha .
3
String s = new String("Mom");
String s2 = s;
System.out.println(s == s2);
Bandingake referensi .
bener bakal ditampilake ing layar.
Loro-lorone variabel nyimpen referensi menyang obyek sing padha .
4
Cat cat1 = new Cat("Oscar");
Cat cat2 = new Cat("Oscar");
System.out.println(cat1 == cat2);
Bandingake referensi .
palsu bakal ditampilake ing layar.
Rong variabel kasebut nuduhake obyek Cat sing padha, nanging ora padha.
5
String s = new String("Mom");
String s2 = new String("Mom");
System.out.println(s == s2);
Bandingake referensi .
palsu bakal ditampilake ing layar.
Loro variabel kasebut ngrujuk obyek String sing padha, nanging ora padha.
6
String s = new String("Mom");
String s2 = new String("Mom");
System.out.println(s.equals(s2));
Mbandhingake obyek .
bener bakal ditampilake ing layar.
Loro variabel kasebut ngrujuk obyek String sing padha

"Oh, aku meh lali! Iki sawetara latihan kanggo sampeyan:"

4
tugas
Java Syntax,  tingkatwulangan
Dikunci
Minimum of two numbers
All search and sort algorithms are based on comparisons. You'll be able to handle these very soon, if you so desire. In the meantime, we suggest starting with something small: write a program to find the minimum of two numbers. Find it and then display it. And if the numbers are the same, display either of them.
4
tugas
Java Syntax,  tingkatwulangan
Dikunci
Maximum of four numbers
Finding the maximum is an n-ary operation (an operation on n numbers) that returns the largest of several numbers. Never mind. We have no need for such definitions at the secret CodeGym center. We're here to learn how to write code. In this task, you need to use the keyboard to enter four numbers. Then determine the largest of them and display it on the screen.
8
tugas
Java Syntax,  tingkatwulangan
Dikunci
Sorting three numbers
Planet Linear Chaos is populated by isomorphs. They are believed to have invented sorting algorithms. Everything in their heads is extremely well-ordered. They only issue planetary visas to people who know at least 7 sorting algorithms. Let's take our first step toward Linear Chaos: Read three numbers from the keyboard, put them in descending order, and then display them on the screen.
4
tugas
Java Syntax,  tingkatwulangan
Dikunci
Jen or Jen?
Jen, Company X's admin, learned how to pilot a space ship and flew away to another planet. People in Company X are good and sincere. It's just that they're scatterbrained and they mix up names. So they decided that the new administrator would also be called Jen. Let's help Company X find their Jen: write a program that checks the identity of two entered names.