Java 08 - Latihan Input (Membuat Program Sederhana dengan Java) - Tutorial Java Netbeans Indonesia
Summary
TLDRThis video tutorial focuses on Java programming, guiding viewers through creating a simple program that accepts user input for name, address, and age. The presenter demonstrates how to utilize the Scanner class to gather input and store it in variables. They then format and display the input data in a structured manner, ensuring the output is neatly organized. The tutorial also touches on the use of escape sequences to enhance the presentation of the data, encouraging viewers to practice and refine their coding skills for better data handling and presentation.
Takeaways
- 😀 The video is a tutorial on Java programming focusing on handling user input.
- 💻 The presenter demonstrates how to create a simple Java program for inputting data such as name, address, and age.
- 📝 The program is designed to display the inputted data in a formatted manner, showing the entered information as a sentence.
- 🔧 The tutorial uses the Java Development Kit (JDK) and the Integrated Development Environment (IDE) to create a new Java project.
- 📂 The project is named 'input_data' and is stored within a folder named 'Project Java' alongside other projects.
- 🔑 The 'Scanner' class from the Java utility library is utilized to handle user input within the program.
- 📖 The video explains how to declare variables with specific data types (String for name and address, Integer for age) and assign values to them based on user input.
- 🎯 The tutorial covers the use of the 'System.out.println' method to display prompts and receive input from the user, and 'Scanner' methods like 'next()' and 'nextInt()' to read the input.
- 📊 The presenter shows how to format the output using escape sequences to align text properly in the console, enhancing readability.
- 🔗 The video concludes by encouraging viewers to practice and possibly improve upon the provided code to better suit their needs.
Q & A
What is the main topic discussed in the video?
-The main topic discussed in the video is how to create a Java program for inputting data, specifically for entering a person's name, address, and age, and then displaying that information in a formatted manner.
What programming language is used in the video?
-The programming language used in the video is Java.
What is the purpose of the 'scanner' library mentioned in the video?
-The 'scanner' library in Java is used to obtain input from the user, allowing the program to read data such as text and numbers.
How does the video demonstrate the use of the 'scanner' library?
-The video demonstrates the use of the 'scanner' library by importing it and using it to create an object that can read user input for variables like name, address, and age.
What is the significance of the 'System.out.println()' method in the context of the video?
-The 'System.out.println()' method is used in the video to display output to the console, such as prompts for user input and the formatted display of the entered data.
What is the role of the 'public static void main' method in the Java program discussed?
-The 'public static void main' method serves as the entry point of the Java program, where the execution of the program begins.
How does the video guide the creation of variables for storing user input?
-The video guides the creation of variables by declaring them with appropriate data types (string for name and address, integer for age) and then using the 'scanner' object to assign values from user input to these variables.
What is the purpose of the 'nextLine()' and 'nextInt()' methods in the context of the video?
-The 'nextLine()' method is used to read a line of text from the user, while 'nextInt()' is used to read an integer. These methods are part of the 'scanner' library and are used to capture different types of user input.
How does the video address the formatting of the output?
-The video addresses the formatting of the output by using 'System.out.println()' to structure the displayed information in a readable format, such as 'Name was born in Address, age Years old'.
What is an 'Escape sequence' as mentioned in the video?
-An 'Escape sequence' refers to a special sequence of characters that is used to represent a character that is not readily representable, such as a tab or a newline. In the video, it is used to format the output by adding spaces or tabs.
What is the final output the video aims to achieve with the Java program?
-The final output the video aims to achieve is a formatted string that includes the user's name, address, and age, displayed in a clear and structured manner, such as 'Alex was born in Nganjuk, 19 years old'.
Outlines
💻 Introduction to Java Programming
The speaker begins by greeting the audience and proceeds to discuss the continuation of Java programming lessons. The focus of this video is on how to create a program for inputting data, which was previously discussed. The speaker demonstrates a simple program that allows users to input a name, address, and age. Upon entering the data, it is formatted and displayed according to a predefined format. The speaker guides the audience through the initial steps of opening a new project in Java, naming it 'input_data', and organizing it within a 'Project Java' folder. The speaker emphasizes the importance of keeping files organized for easy access and use.
📝 Setting Up Java Input Program
The speaker instructs the audience to clean up any comments in the code and sets up the main class with a 'public static void main' method. The program utilizes the Scanner library to handle user input, which is imported from the Java standard utility library. The speaker explains the process of declaring variables to store the user's name, address, and age, with appropriate data types (String for name and address, and Integer for age). The speaker then demonstrates how to prompt the user for input using 'System.out.println' and how to read the input using the Scanner object. The video provides a step-by-step guide on how to input data, store it in variables, and then display it in a formatted manner.
🔍 Processing and Displaying User Input
The speaker continues by showing how to process the input data and display it in a formatted string. The program concatenates the user's name, address, and age into a sentence that is then printed to the console. The speaker also covers the use of escape sequences to improve the formatting of the output, such as adding spaces between words. The video concludes with a demonstration of the complete program in action, showing how the user's input is taken, processed, and displayed in a clean and organized manner. The speaker encourages the audience to experiment with different data and to improve the text display as desired.
Mindmap
Keywords
💡Java
💡Input
💡Scanner
💡Variables
💡Data Types
💡IDE (Integrated Development Environment)
💡Main Method
💡System.out.println
💡Escape Sequence
💡Project
💡Compilation
Highlights
Introduction to Java programming and continuation of previous discussions.
Explanation of creating a program for input that organizes data in a specific format.
Demonstration of a simple program interface for inputting name, address, and age.
Guide on creating a new Java project and naming conventions.
Importing the Scanner library for input handling in Java.
Utilizing the Scanner library to capture user input for a string variable.
Declaring multiple string variables in a single line for efficiency.
Using System.out.println for displaying prompts to the user.
Capturing input for the 'name' variable using the Scanner library.
Explanation of using 'next()' method for string inputs in the Scanner library.
Guide on inputting and capturing the 'address' variable.
Capturing the 'age' variable as an integer using the Scanner library.
Combining variables to display formatted output with user input.
Demonstration of the program's output with sample inputs.
Introduction to using escape sequences for better text formatting in output.
Using backslashes for tabs and line breaks in System.out.println for cleaner output.
Final program demonstration with formatted output and user inputs.
Encouragement for viewers to improve and develop their own text display patterns.
Conclusion of the tutorial with a sign-off and well-wishes.
Transcripts
hai
[Musik]
oke Salamualaikum teman-teman semuanya
kita akan melanjutkan pembahasan kita di
pemrograman java dan di video kali ini
kita akan coba ulas Gimana cara kita
membuat program untuk inputan yang
sebelumnya sudah kita bahas sehingga
nanti kita bisa membuat program
sederhana yang tampilannya seperti ini
kita bisa menginputkan nama semisal di
sini saya mengetikkan Alex
terus kita bisa mengetikkan alamat
dan yang terakhir kita bisa mengetikkan
umur dan kalau ini kita enter semua data
yang kita inputkan disini akan tersusun
sesuai dengan format yang kita buat dan
disini saya buat seperti ini dari data
yang kita inputkan di atas di bawah sini
saya Tampilkan sebagai kalimat seperti
ini nah gimana cara pembuatannya solusi
maksudnya sampai selesai seperti
[Musik]
udah temen-temen langkah awal kita buka
untuk id-nya disini saya tetap
menggunakan IDM nya teman-teman Jadi
silakan dibuka untuk apa JNE duitnya
kita akan coba buat program baru di
Hai Langsung aja temen-temen kita buat
projectnya disini untuk yang di kategori
dan juga Project kita biarkan Aceh jadi
kita biarkan default seperti biasanya
untuk nama Project nya sekarang kita
masuk di video ke-8 temen-temen jadi
saya kasih apa ini delapan underscore
kita akan bahas tentang input jadi saya
kasih aja tulisan input data yakin Iya
tujuan the score input data Nah untuk
lokasi penyimpanannya saya akan
kelompokkan dengan project-project
sebelumnya teman-teman sebelumnya saya
simpan di Project Java nah saya biarkan
berkumpul dengan teman-temannya di sini
ada di sini ada video sampai 07 ya
sekarang kita masuk ke video 8 jadi
langsung aja ke saya klik Open jadi
disini projectnya terkumpul semuanya di
folder Project Java Terserah kalian
kalian kumpulkan di folder apapun yang
penting kalian gak bingung kalau
sewaktu-waktu kita perlu programnya
kalian bisa mencarinya dan file-nya bisa
terlantar api temen-temen Nah untuk yang
lainnya kita biarkan default aja kita
sekarang klik finish Hai Nah sekarang
untuk yang komen-komen ini saya
bersihkan dulu teman-teman jadi biar
Spesialnya itu agak banyak gaya
temen-temen saya sisakan seperti ini ya
saya tinggalkan public class sama public
Static void main ini karena di video
kali ini kita akan memanfaatkan input
jadi kita akan memanfaatkan si library
scanner teman-teman yang sudah tersedia
di Java kalau kalian ingat di video
sebelumnya kita sudah ulas Gimana
caranya kita menggunakan library scanner
caranya kita langsung impor aja dari ide
ini tempat dari tersimpannya sih
lebreros scanner teman-teman jadi kita
impor untuk foldernya itu namanya Java
terus untuk letak dari PGC itu namanya
yu'til atau utility dari sih program
Java itu dan untuk nama library nya itu
adalah scanner
Oke kalian ketikan seperti ini aja
temen-temen ya ini titiknya kelebihan
satu temen-temen oke Hai kalau sudah
sekarang kita masuk ke kelas utama kita
yaitu di klasemein saya akan masuk di
public Static void disini nah untuk
pemanggilan atau penggunaan dari scanner
kita harus memanggil library itu di
dalam kelas main kita atau ditempat kita
menjalankan program utama cara
pemanggilannya seperti biasa temen-temen
kita ini siapkan atau kita memberikan
identifier terhadap sih library scanner
caranya kita Panggil dulu Apa nama
library nya scanner kita kasih
identifier apa input jadi untuk input
itu identifier nya terserah kalian
kalian mau kasih nama apa terserah
disini biar saya nggak bingung saya
kasih nama input biar kalau nanti saya
ingin melakukan input data ke dalam
sebuah variabel tinggal saya panggil sih
identifier input otomatis kita akan
terhubung ke library scanner gitu
nah identifier input ini adalah
pemanggilan objek dari si scanner
dengan parameter
temps.id
Nah untuk pemanggilan dari library
scanner nya sudah berhasil teman-teman
Sekarang kita akan coba buat beberapa
variabel yang akan kita gunakan sesuai
dengan program tadi teman-teman yang
pertama tadi kita perlu sebuah variabel
yang akan kita gunakan untuk menampung
nama karena nama itu bentuknya teks ya
teman-teman Jadi kita akan menggunakan
tipe data string untuk identifier atau
variabelnya saya akan kasih nama ya nama
ajar ini selanjutnya tadi kita punya
variabel yang akan kita gunakan untuk
menyimpan data alamat karena alamat itu
juga teks maka Disini saya akan
menggunakan tipe data string nama
variabelnya adalah alamat untuk
selanjutnya tadi saya perlu umur
teman-teman Karena umur disini saya
nggak mau ada koma koma nya ya kita
anggap aja dia bilangan bulat jadi saya
akan buat variabel dengan tipe data
integer namanya adalah umur nah udah
kayak gini teman-teman nah kita bisa
mencederai enakan di sini ada dua yang
tipe datanya adalah string yaitu nama
dan juga alamat Disini saya akan coba
singkat untuk deklarasinya jadi Nama dan
alamat saya deklarasikan dalam satu
baris karena dua-duanya sama tipe
datanya yaitu sering teman-teman Oke
gitu ya untuk deklarasi perdagangan
ASEAN ini udah beres Sekarang kita akan
Coba lakukan input data sebelum
melakukan input data kita akan berikan
label yang tampil tadi temen-temen nama
titik dua baru di sebelahnya kita
inputkan data ya karena kita ingin
menampilkan sesuatu maka kita
menggunakan system.in sebelumnya kita
udah ngebahas temen-temen kalau kita
bisa menggunakan shortcut caranya
ketikan aja south-south lalu kalian TP
dia otomatis muncul system.in Land tapi
ini default-nya system.out println ada
LN nya kalau ini kita biarkan semisal
nama kita nanti menginputkan nama
tradisi Nikita Panggil untuk cinta
scanner untuk menginputkan data ke
variabel nama yang tipe datanya string
caranya variabel nama itu adalah
identifier dari lebar scanner yang sudah
kita deklarasikan di atas ini apa input
ya teman-teman kita berikan dot selalu
perintah yang kita jalankan di dalam
library scanner itu adalah next
apa kalau sering kemarin kita
menggunakan next selain karena next
selain kita gunakan untuk memberikan
inputan lebih dari satu kata jadi ada
spasinya bisa kalau enggak ada lainnya
kita menggunakan next saja Berarti dia
enggak ada spasinya teman-teman gitu
kalau ini kita simpan terus coba kita
jalankan
dia inputannya ada di bawah dari teks
atau narasi yang kita buat teman-teman
kita lihat di sini ya nama kalau kita
ketikkan sesuatu semisal Alex
jadi akan tampil di bawahnya teman-teman
Gimana caranya kalau kita ketikkan nama
dia letaknya langsung di sebelah
kanannya dari titik dua ini caranya LN
ini kita hapus jadi kita melakukan
perintah system.in kalau dot println dia
bisa memberikan enter kalau doktrin aja
dia disampingnya jadi nggak turun ke
bawah gitu ceritanya teman-teman Nah
kalau sudah kita coba jalankan sekali
lagi
Oh ya kalau kita menginputkan sesuatu
Alexander Kurniawan
Nah dia langsung disampingnya
disampaikan tanpa Dia memberikan enter
di bawahnya Oke langkah selanjutnya tadi
kita memberikan input berupa alamat Ya
udah ini kalian copy aja temen-temen
kalau kalian males ngopi Ya udah ketik
aja sout terus LN nya kalian Hapus
sini Kasih alamat
di bawahnya baru kita berikan inputan
terhadap variabel alamat yang tipe
datanya string kita panggil aja
variabelnya alamat itu adalah si
identifier dari scanner input
dotnya karena dia string alamat bisa
dong kita nanti memberikan lebih dari
satu kata berarti Dotnet lainnya
teman-teman
oke alamat sudah beres kita coba nanti
aja yang terakhir kita punya variabel
umur temen-temen ya karena umur ini
adalah integer jadi di sini bentar kita
tampilkan SD dulu sout
untuk perintah Hai menginputkan umur ya
berarti umur titik dua di bawahnya kita
berikan hak enter kita berikan
dibawahnya variabel umur yang tipe
datanya adalah integer itu adalah
identifier dari scanner input karena
tipe datanya integer di sini kita
berikan next
imd jangan lupa di adalah method ya Jadi
ada kurung buka kurung tutup nya di
belakang Oke kalau sekarang kita
jalankan kita sudah berhasil membuat
inputan seperti ini nama semisal Alex
langsung muncul di bawahnya alamat
semisal Nganjuk
dibawahnya kita ada perintah untuk
menginputkan umur semisal umurnya 22 Oke
inputan udah beres untuk teks yang kita
inputkan ini sudah berhasil harusnya
berhasil masuk ke dalam variabel tinggal
kita proses untuk variabel itu kita
apakan ya karena tadi kita tampilkan
berupa susunan teks ya di bawahnya sini
jadi pm2 dibawahnya sini pembatas dulu
teman-teman
sout kita akan berikan gini sama dengan
yang banyak oke dia println karena kita
ingin memberikan enter setelahnya
dibawahnya sini kita sout lagi ya
kayaknya ini ya kepakai println gak
masalah namanya kita tampilkan disini
variabelnya adalah nama Terus mungkin ya
mungkin saya berikan Oh gini aja
temen-temen nama terus disampingnya kita
berikan
lahir di terus disini kita hubungkan
dengan variabel alamat
Terus di bawahnya jadi turun ke bawah ya
Jadi nanti tampil di sini namanya
semisal Alex jadi Alex lahir di
alamat-alamat Nganjuk berarti Alex lahir
di Nganjuk terheboh sini kita berikan
berumur
baru di sini kita hubungkan dengan
variabel umur umurnya berapa yang kita
inputkan kalau 22 ke-22 di belakangnya
kita berikan redaksi spasi th gitu aja
atau tahun gitu ya teman-teman
Oke sekarang kita coba jalankan sekarang
saya inputkan namanya Alex
alamatnya Nganjuk
umurnya semisal 19 dia akan tampil
seperti ini Alex lahir di Nganjuk
berumur 19th itu ya teman-teman Coba
kita menggunakan data yang lain semisal
Bisma
Bisma l gitu ya biar lebih dari satu
kata alamatnya Kediri kota oke umurnya
29 Oke Bisma l lahir di Kediri kota
berumur 29th Oke Mantap ya teman-teman
berarti pemanfaatan variabel umtuk kita
proses diproses selanjutnya udah beres
kita punya variabel kosong ya jadi
disini variabel kosong semua nama alamat
umur
cara mendeklarasikan variabel dengan
tipe data tertentu tapi enggak ada value
atau isinya baru di bawah sini
variabelnya kita isi dengan data sesuai
keinginan kita teman-teman enggak sampai
situ aja setelah datanya kita masukkan
ke dalam variabel di bawah sini variabel
yang sudah kita isi sesuai keinginan
kita kita proses sesuai dengan yang kita
harapkan jadi ada variabel kosong ada
inputannya ada outputnya jelas prosesnya
sudah ada di dalam situ teman-teman nah
gitu nah disini masih ada sesuatu
kekurangan yang sebelumnya sudah kita
bahas tapi belum kita terapkan yaitu
pemanfaatan Escape sequence menurun
karena titik2nya ini masih blepotan
masih berantakan ya deh di depan ada
yang ditengah ada yang di belakang
Sekarang kita akan rapikan menggunakan
Escape squash kalau kalian ingat cara
merapikan teks seperti ini kita bisa
memanfaatkan yang namanya backup selesai
stay atau step jadi fungsi istimewa atau
karakter istimewa untuk memberikan Tab
di dalam output system.in
kita berikan bexley terhadap narasi atau
menjadi narasinya kita kasih website
semuanya di sebelumnya titik dua pasca
teman-teman Coba kita save terus coba
kita jalankan
Nah sekarang sudah ada Spesialnya antara
nama dan titik dua Ada jaraknya sekitar
beberapa
spasi temen-temen Coba kita ketikkan
Alex k
Nah sudah rapi temen-temen ya antara
titik dua yang atas sama titik dua yang
bawah itu sudah ada sudah apa ya sudah
sama rapi teman-teman coba alamatnya
Ngawi
umurnya
17 Nah kan ini lebih rapi daripada tadi
temen-temen titik2nya sudah sesuai
dengan
atasnya Ya sudah satu baris gini Oke
mungkin itu ya teman-teman pembahasan
kita untuk latihan di sini Kita sudah
berhasil berlatih Untuk memanfaatkan
input data didalam sebuah variabel yang
sudah kita deklarasikan dengan enggak
ada data Ya maksudnya variabel kosong
terus kita isikan data terus datanya
kita proses di bawah mau kita apakan
Terserah kalian ia untuk redaksi yang
saya buat seperti ini kalau kalian mau
improve silahkan ya temen-temen kalian
coba otak-atik gimana teks yang ingin
kalian Tampilkan polanya Seperti apa
silahkan kalian improve atau kembangkan
sendiri so mungkin itu pembahasan kali
ini semoga bermanfaat
terus saksikan video selanjutnya saya
kiri wassalamu'alaikum warahmatullahi
wabarakatuh
[Musik]
Weitere ähnliche Videos ansehen
How to Program A Calculator in C++! (Great C++ Microsoft Visual Studio Beginner Project)
C++ Validating Input with a while Loop
41. OCR A Level (H046-H446) SLR8 - 1.2 Introduction to programming part 2 variables & constants
CARA MENGGUNAKAN NVIVO : INPUT DATA, CODING, DAN VISUALISASI DATA KUALITATIF
How to Become an AI Prompt Engineer For Beginners
TUGASS PRESENTASI PEMOGRAMAN 1 KELOMPOK 7
5.0 / 5 (0 votes)