[Java] Praktikum 3 : untuk mencari nilai rata

-[Java] Praktikum 3 : untuk mencari nilai rata ini merupakan lanjutan dari postingan : ALGORITMA DAN PEMROGRAMAN MODUL 1 SUB PROG...

-[Java] Praktikum 3 : untuk mencari nilai rata

ini merupakan lanjutan dari postingan :

ALGORITMA DAN PEMROGRAMAN

MODUL 1 SUB PROGRAM (Procedure & Function).


c. Praktikum 3


import java.util.Scanner;
public class Rata
{
//var global untuk:
//var utk banyak data
//var utk menghitung total nilai yg diinputkan sebanyak n

private static int n;
private static int total = 0;
public double hitungRata (int jumlah, int ndata)//fungsi
{
// var jumlah fungsinya = var total
// var ndata = n
//fungsi hitungRata=jumlah/ndata
return (jumlah/ndata);
}
public void masukNilai(int jlh, int k)//prosedur
{
//var jlh = var jumlah di hitungRata = var total
//var k = var ndata = var n
Scanner input = new Scanner (System.in);
System.out.print("Masukkan banyak data: ");
k = input.nextInt();
jlh = 0;
for (int i=1; i<=k; i++)
{
System.out.print("Data ke-"+i+": ");
int x = input.nextInt();
jlh = jlh + x;
}
System.out.println("Banyak data: " + k);
System.out.println("Jumlah data: " + jlh);
System.out.println("Rata-ratanya: "+hitungRata(jlh,k));
}
public static void main (String[] args)//method utama
{
new Rata().masukNilai(total,n);
}
}


Hasil output :







Demikian contoh  Pratikum (Procedure dan Function). semoga bermanfaat.


COMMENTS

BLOGGER

Nama

Artikel,66,Cerita singkat,82,Java,12,SEO,15,Tahukah sobat??,21,Tips dan Trik,15,Tips.....n' Trick.....,14,Tutorial,20,Tutorial Blogger,50,
ltr
item
Blog Salman Syuhada: [Java] Praktikum 3 : untuk mencari nilai rata
[Java] Praktikum 3 : untuk mencari nilai rata
https://4.bp.blogspot.com/-BkHYtO3Hn34/T8HOOc31yWI/AAAAAAAABTA/Ydw6TrS1Qz8/s1600/java.jpeg
https://4.bp.blogspot.com/-BkHYtO3Hn34/T8HOOc31yWI/AAAAAAAABTA/Ydw6TrS1Qz8/s72-c/java.jpeg
Blog Salman Syuhada
http://blog.salmansyuhada.com/2012/05/praktikum-3.html
http://blog.salmansyuhada.com/
http://blog.salmansyuhada.com/
http://blog.salmansyuhada.com/2012/05/praktikum-3.html
true
5369818979434965955
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy