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 :
Posted by Dyah Ayu Cintya Posted on 06.08 | No comments

Menghitung Rata-Rata dengan Metode 3 Inputan JOption

Berikut adalah coding untuk menghitung rata - rata dengan Metode JOption >>

package Latihan;

import javax.swing.JOptionPane;
public class Input3_JOption {

      public static void main(String[] args) {
      
        int n1 = Integer.parseInt(JOptionPane.showInputDialog("Masukkan n1: "));

        int n2 = Integer.parseInt(JOptionPane.showInputDialog("Masukkan n2: "));

        int n3 = Integer.parseInt(JOptionPane.showInputDialog("Masukkan n3: "));
       
        int rata = (n1+n2+n3)/3;

        JOptionPane.showMessageDialog(null,"Nilai rata-rata dari semua data adalah : "+rata);
    }

}

Hasil Outputnya seperti ini ...
 
 






 
Hasil Rata - Rata :

Selamat Mencoba... :)
Semoga Bermanfaat ^_^