Latihan -4 Bahasa Pemrograman Java

BAB 5
Mendapatkan Input dari Keyboard

Jawaban 5.1 Latihan
5.1.1 Kata Terakhir (versi BufferedReader)

import java.io.*;

public class latinput {
public static void main( String[] args ){
BufferedReader dataIn = new BufferedReader(new
InputStreamReader( System.in) );
String name1 = "";
String name2 = "";
String name3 = "";


System.out.print("Masukkan Kata Pertama:");
try{
name1 = dataIn.readLine();
}catch( IOException e ){
System.out.print("Error!");
}

System.out.print("Masukkan kata Kedua:");
try{
name2 = dataIn.readLine();
}catch( IOException e ){
System.out.print("Error!");
}

System.out.print("Masukkan Kata Ketiga:");
try{
name3 = dataIn.readLine();
}catch( IOException e ){
System.out.print("Error!");
}
System.out.println(name1 + " " + name2 +" "+ name3 );
}
}


5.1.2 Kata Terakhir (versi JOptionPane)

import javax.swing.*;
public class latinputjopton {
public static void main( String[] args ){
String namedepan = "" , namebelakang = "";

namedepan = JOptionPane.showInputDialog("Silahkan masukkan nama depan");
namebelakang = JOptionPane.showInputDialog("Silahkan masukkan nama belakang ");
String msg = namedepan +" "+ namebelakang;
JOptionPane.showMessageDialog(null, msg);
}
}

No comments:

Post a Comment