Mesran

Hanya ingin berbagi kebaikan dan mendapatkan kebaikan yang lain.

Praktek : Latihan Perulangan dan Array pada Java

Buatlah program untuk menginputkan beberapa buah nilai, dan mencari total nilai serta rata rata dari nilai yang di masukkan.

Jawaban kasus yaitu :

Nama file rata2.java

import java.io.* ;
public class rata2{
	public static void main(String Arg[]) throws IOException{

   		int nilai[ ] ;
    		nilai = new int[20] ;
    		double rata = 0, total = 0  ;

    		String str       ;
    		int i, jdata ;

    		BufferedReader Get=new BufferedReader(new InputStreamReader(System.in)) ;

    		System.out.println("Menghitung Nilai Rata Rata") ;

    		System.out.print("Jumlah Data :")  ; str = Get.readLine() ;
    		jdata = Integer.parseInt(str) ;

    		for (i = 0; i<jdata ; i++){
    		System.out.print("Nilai ke : "+ (i+1) + " : ") ;
    			str = Get.readLine() ;
    			nilai[i] = Integer.parseInt(str) ;
    		}

    		rata = 0 ; total = 0 ;
    		System.out.println("Menghitung Nilai Rata Rata") ;

    		for (i = 0; i<jdata ; i++){
    			System.out.println("Nilai ke : "+ (i+1) + " : "+nilai[i]) ;
    			total = total + nilai[i] ;
    		}

   	 	rata = total / jdata ;
    		System.out.println("Total Nilai : "+ total) ;
    		System.out.println("Nilai Rata-Rata : "+ rata) ;

	}
}

Hasil Program :

Advertisements

Filed under: Java 2 SE,

One Response

  1. Deni says:

    Mantaps pak 😀

Terima kasih telah memberikan komentar anda.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives Per Tahun

%d bloggers like this: