Rabu, 21 September 2011

Posted by Dyah Ayu Cintya Posted on 06.27 | 1 comment

Menghitung Rata - rata dengan 3 Metode Input User

Langsung saja pada Codingnya yaaa...

package Latihan;

import java.io.*;                          
import java.util.Scanner;

import javax.swing.JOptionPane;


public class Rata3inputan {
    public static void main(String[] args) {
        Scanner Input = new Scanner(System.in);
        System.out.print("Masukkan Nilai 1(N1) : ");
        int n1 = Input.nextInt();
       
        try{
            BufferedReader Input2 = new BufferedReader(new InputStreamReader(System.in));
            System.out.print("Masukkan Nilai 2(N2) : ");
            Integer n2 = Integer.parseInt(Input2.readLine());
                       
            int n3 = Integer.parseInt(JOptionPane.showInputDialog("Masukkan N3 : "));
            int rata = (n1+n2+n3)/3;
            JOptionPane.showMessageDialog(null,"Nilai Rata -rata dari: " +"\n"+n1+"  "+n2+"  "+n3+"   adalah \n"+ rata);   
        }
        catch(Exception e){
            System.out.println(e);
        }
    }
   
}



Hasil Output yang tertampil seperti berikut :