- Back to Home »
- BufferedReader , Java »
- Contoh Program Java Menggunakan Input dengan BufferedReader
Contoh Program BufferedReader
package contoh2;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main
{
public static void main ( String[] args ) throws IOException {
BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) );
String nama;
int nilai;
try{
System.out.print (“Ketikkan nama = “);
nama = (dataIn.readLine());
System.out.print (“Masukkan nilai = “);
nilai = Integer.parseInt(dataIn.readLine());
if (nilai >= 80){
System.out.println(“Ketikkan Nama Anda : ” +nama+ “Nilai Anda : ” +nilai+ “predikat A”);}
else
if (nilai >= 70){
System.out.println(“Ketikkan Nama Anda : ” +nama+ ” Nilai Anda : ” +nilai+ ” predikat B”);}
else
if (nilai >= 60){
System.out.println(“Ketikkan Nama Anda : ” +nama+ ” Nilai Anda : ” +nilai+ ” predikat C”);}
else
if (nilai >= 50){
System.out.println(“Ketikkan Nama Anda : ” +nama+ ” Nilai Anda : ” +nilai+ ” predikat D”);}
else {
System.out.println(“Ketikkan Nama Anda : ” +nama+ ” Nilai Anda : ” +nilai+ ” predikat E”);}
}
catch( NumberFormatException e ){
System.out.println(“Error!”);
System.exit(1);
}
}
}
Sumber: http://andrie07.wordpress.com/2010/11/12/contoh-program-bufferedreader-contoh-program-joptionpane/