Upload presentasi
Presentasi sedang didownload. Silahkan tunggu
1
MENDAPATKAN INPUT DARI KEYBOARD
2
Tujuan Membuat program kita lebih interaktif dengan menggunakan input dari keyboard Menggunakan kelas BufferedReader dan melalui GUI (Graphical User Interface) dengan menggunakan kelas JOptionPane.
3
Menggunakan BufferedReader
Tambahkan di bagian paling atas code anda: import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; Tambahkan dibawah viod main : BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) );
4
Contoh package inputkey; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.IOException; public class Main{ public static void main( String[] args ){ BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) ); String name = ""; System.out.print("Please Enter Your Name:"); try { name = dataIn.readLine();} catch( IOException e ){ System.out.println( " Error ");} System.out.println("Hello " + name + " ! "); }}
5
package inputkey; import java.io.*; public class Main { public static void main( String[] args ) BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) ); String name = ""; System.out.print("Please Enter Your Name:"); try name = dataIn.readLine(); } catch( IOException e ) System.out.println( " Error "); System.out.println("Hello " + name + " ! ");
6
Menggunakan Scanner Tambahkan di bagian paling atas code anda:
import java.util.*; Tambahkan dibawah viod main : Scanner baca = new Scanner(System.in);
7
package satu; import java.util.*; public class Main { public static void main(String[] args) Scanner baca = new Scanner(System.in); int nilai; System.out.print(“Input Anda = "); nilai = baca.nextInt(); System.out.println("Nilai Anda = " +nilai); }
8
Menggunakan JOptionPane
Tambahkan di bagian paling atas code anda: import javax.swing.JOptionPane; Tambahkan dibawah viod main : name = JOptionPane.showInputDialog("Please enter your name"); String msg = "Hello " + name + "!"; JOptionPane.showMessageDialog(null, msg);
9
package jopt; import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { String name = ""; name = JOptionPane.showInputDialog("Please enter your name"); String msg = "Hello " + name + "!"; JOptionPane.showMessageDialog(null, msg); }
10
Latihan A = B = C = A * B Buat dengan BufferedReaderdan Joption Pane
Presentasi serupa
© 2024 SlidePlayer.info Inc.
All rights reserved.