"Dulu, komputer mung bisa nampilake teks. Program nampilake data ing layar sawise nampa input saka keyboard. Iki diarani 'antarmuka pangguna konsol' utawa mung 'konsol'. Antarmuka jendhela minangka alternatif kanggo konsol. Kanthi antarmuka jinis iki, pangguna sesambungan karo program liwat siji utawa luwih windows. Awit kita lagi sinau carane program, kita bakal miwiti karo nggarap console."

"Inggih."

"Teks ditampilake ing konsol (layar) kanthi berturut-turut, baris demi baris. Teks kasebut dilebokake nggunakake keyboard. Kanggo ngindhari kesalahan, input keyboard ditampilake ing layar. Kadhangkala katon kaya pangguna manungsa lan program kasebut gantian . nulis barang ing layar. "

"Sampeyan bisa nggunakake metode System.out.print () kanggo nampilake teks ing layar. Cara iki mung nampilake teks, nalika System.out.println () nampilake teks lan mindhah kursor menyang baris sabanjure."

Kode asil
System.out.print("Rain");
System.out.print("In");
System.out.print("Spain");
RainInSpain
System.out.print("Rain");
System.out.println("In");
System.out.print("Spain");
RainIn
Spanyol
System.out.println("Rain");
System.out.println("In");
System.out.println("Spain");
Udan
ing
Spanyol

"Kanggo misahake potongan teks, kita kudu nambah spasi. Contone:"

Kode asil
int a = 5, b = 6;
System.out.print(a);
System.out.print(b);
56
int a = 5, b = 6;
System.out.print(" " + a + " " + b);
 5 6
int a = 5, b = 6;
System.out.print("The sum is " + (a + b));
The sum is 11

"Ngerti"

"Iki ngidini sampeyan nampilake apa wae ing layar: kabeh obyek Jawa bisa diowahi dadi string. Kabeh kelas Jawa asale saka kelas Obyek, sing nduweni metode toString(). Cara iki diarani nalika sampeyan pengin ngowahi obyek dadi a string."

Kode Katrangan
Cat cat = new Cat("Oscar");
System.out.println("The cat is " + cat);
Telu conto iki padha.
Cat cat = new Cat("Oscar");
System.out.println("The cat is " + cat.toString());
Cat cat = new Cat("Oscar");
String catText = cat.toString();
System.out.println("The cat is " + catText);
3
tugas
Java Syntax,  tingkatwulangan
Dikunci
Display right away
Programming isn't always difficult. Sometimes you need to do simple tasks. And the more similar tasks you have to do, the more you want to automate them. Let's implement one more method. Ultimately, objects without methods don't do anything. We'll pass the string s to the method, which will then display it on the screen.

"Nanging program sandi ditampilake ' Kucing punika com.codegym.lesson3.Cat@1fb8ee3 '. Apa ing donya iki mestine kanggo tegese?"

"Metode toString standar kelas Obyek () ngasilake senar sing kalebu jeneng kelas lan alamat memori obyek (ing wangun heksadesimal)."

"Uh-huh. Lan apa gunane sing bisa teka saka cara kaya mengkono?"

"Sampeyan bisa nulis implementasine dhewe toString () ing kelas. Banjur iku cara sing bakal disebut.

"Tenan? Nggih."

"Iki sawetara tugas saka Diego."

3
tugas
Java Syntax,  tingkatwulangan
Dikunci
Currency exchange
Loan sharking, sales, banking: do you have a backup plan if programming doesn't work out? No? In that case, let's help traders and financiers with our top-notch programs. First, we'll organize a currency exchange: write a program that converts euros to dollars at a given exchange rate.
3
tugas
Java Syntax,  tingkatwulangan
Dikunci
Task with percentages
If you weren't afraid of problems with percentages in school, then this problem won't scare you either. But if you do suddenly find yourself afraid, it's time to face your fear and realize that this is actually a simple and pleasant topic. Let's implement a method that increases the passed integer by 10 percent.
1
tugas
Java Syntax,  tingkatwulangan
Dikunci
Code entry
Your attention, please! Now recruiting code entry personnel for CodeGym. So turn up your focus, let your fingers relax, read the code, and then... type it into the appropriate box. Code entry is far from a useless exercise, though it might seem so at first glance: it allows a beginner to get used to and remember syntax (modern IDEs seldom make this possible).