Friday, September 16, 2011 - 1 comments

Input data dengan 3 statement berbeda

Hasil Output :









Code :

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import javax.swing.JOptionPane;

public class Input_dengan_3_cara_berbeda {
    public static void main(String args[])
    {
        double N1, N2 = 0, N3, NR;
       
        String n3;
       
       
        Scanner nilai1 = new Scanner(System.in);
       
        System.out.print("Masukan nilai pertama \t : ");
        N1 = nilai1.nextDouble();
       
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        try
        {
            System.out.print("Masukkan nilai kedua \t : ");
            N2 = Integer.parseInt(in.readLine());
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
       
        n3 = JOptionPane.showInputDialog("Masukkan nilai ketiga : ");
        N3 = Integer.parseInt(n3);
       
        //proses
       
        NR = (N1 + N2 + N3) / 3;
       
        JOptionPane.showMessageDialog(null, NR);
    }
}

1 comments:

Anonymous September 23, 2011 at 1:45 PM

Makasih gan... Sangat membantu.,. :)

Keep move!!

Post a Comment