waduh2 . .
bu ninik cute kasih tugas neh...
aseek . .
input dinamis dalam berbagai cara :
-buffered reader
-j option pane
-system console
-scanner
monggo di pacit . .
:: Buffered Reader ::
import java.io.*;
class mhs_buff
{
public static void main(String[]args) throws IOException
{
String temp,nama,nim;
int nilai;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader (isr);
System.out.print("masukkan nama : ");
nama = input.readLine();
System.out.print("masukkan nim : ");
nim = input.readLine();
System.out.print("masukkan nilai : ");
temp = input.readLine();
nilai = Integer.parseInt(temp);
System.out.println("\n:: Data Mahasiswa ::");
System.out.println("nama : "+nama);
System.out.println("nim : "+nim);
System.out.println("nilai : "+nilai);
}
}
:: J Option Pane ::
import javax.swing.JOptionPane;
class mhs_option
{
public static void main(String[]args)
{
String nama="";
String nim="";
String nilaiStr;
int nilai;
nama=JOptionPane.showInputDialog("masukkan nama : ");
nim=JOptionPane.showInputDialog("masukkan nim : ");
nilaiStr=JOptionPane.showInputDialog("masukkan nilai : ");
String msgnama="\nnama : "+nama;
String msgnim="\nnim : "+nim;
String msgnilai="\nnnilai : "+nilaiStr;
JOptionPane.showMessageDialog(null,msgnama);
JOptionPane.showMessageDialog(null,msgnim);
JOptionPane.showMessageDialog(null,msgnilai);
}
}
:: System Console ::
import java.io.Console;
class mhs_console
{
public static void main(String[]args)
{
String nama,nim,nilaiStr;
int nilai;
Console input = System.console();
System.out.print("masukkan nama : ");
nama = input.readLine();
System.out.print("masukkan nim : ");
nim = input.readLine();
System.out.print("masukkan nilai : ");
nilaiStr = input.readLine();
nilai = Integer.parseInt(nilaiStr);
System.out.println("\n:: data mahasiswa ::");
System.out.println("nama : " +nama);
System.out.println("nim : " +nim);
System.out.println("nilai : " +nilai);
}
}
:: Scanner ::
import java.util.Scanner;
class mhs_scanner
{
public static void main(String[]args)
{
String nama,nim,nilaiStr;
int nilai;
Scanner input = new Scanner(System.in);
System.out.print("masukkan nama : ");
nama = input.next();
System.out.print("masukkan nim : ");
nim = input.next();
System.out.print("masukkan nilai : ");
nilaiStr = input.next();
nilai = Integer.parseInt(nilaiStr);
System.out.println("\n:: data mahasiswa ::");
System.out.println("nama : " +nama);
System.out.println("nim : " +nim);
System.out.println("nilai : " +nilai);
}
}
0 komentar:
Posting Komentar