Instruksi :
- Menggunakan perintah masukan melalui keyboard menggunakan perintah BufferedReader.
- Sama seperti no 1 tapi kali ini menggunakan JOptionPane.
(Tugas 1)
nama file : main.java
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
public class Main {
public static void main(String[] args) {
BufferedReader dataln= new BufferedReader(new InputStreamReader(System.in));
String name1 = “”,
name2 = “”,
name3=”“;
try{
System.out.print(“Enter word 1:”);
name1=dataln.readLine();
System.out.print(“Enter word 2:”);
name2=dataln.readLine();
System.out.print(“Enter word 3:”);
name3=dataln.readLine();
}catch(IOException e){
System.out.println(“Error”);
}
System.out.println();
System.out.println(name1+” “+name2+” “+name3);
}
}
*Bagi yang mau digunakan untuk referensi harap di ubah nilai variabelnyaplease…
Output :
Enter word 1:Fendy
Enter word 2:Ferdy
Enter word 3:Desy
Fendy Ferdy Desy
BUILD SUCCESSFUL (total time: 7 seconds)
(Tugas 2)
nama file : main.java
import javax.swing.JOptionPane;
public class Main {
public static void main(String[] args) {
String info=”“;
info=JOptionPane.showInputDialog(“Enter Word1:”);
String data1=info;
info=JOptionPane.showInputDialog(“Enter Word2:”);
String data2=info;
info=JOptionPane.showInputDialog(“Enter Word3:”);
String data3=info;
JOptionPane.showMessageDialog(null, data1+” “+data2+” “+data3);
}
0 Komentar:
Post a Comment