0% found this document useful (0 votes)
5 views1 page

Java Average Calculation with Arrays

The document contains code snippets in Java and C++ demonstrating the use of arrays. The Java code calculates the average of an integer array and prints the values greater than the average. The first C++ code creates a 2D integer array, prompts the user to input values, and prints the full array. The second C++ code defines a 1D integer array, prompts the user to input 5 values, and prints the array.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Java Average Calculation with Arrays

The document contains code snippets in Java and C++ demonstrating the use of arrays. The Java code calculates the average of an integer array and prints the values greater than the average. The first C++ code creates a 2D integer array, prompts the user to input values, and prints the full array. The second C++ code defines a 1D integer array, prompts the user to input 5 values, and prints the array.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

java

import [Link]; public class rata_rata { public static void main(String[] args) { // TODO code application logic here Scanner sc = new Scanner([Link]); int [] x = {2,3,5,6,8}; float rata; int total=0; //hitung total jumlah for (int i=0; i<5; i++) total = total + x[i]; //hitung rata-rata rata = (float) total/5; [Link]("Rata-rata = " + rata); //cari angka yg lebih besar dr rata2 [Link]("Nilai yang lebih besar dari rata-rata : "); for(int j=0; j rata) [Link](x*j+ + ); [Link](); } }

Array 2 Dimensi Berikut Source Code nya :


#include<constream.h> void main() { int n[3][3], x,y; clrscr(); for(x=0;x<=2;x++) { for(y=0;y<=2;y++) { cout<<"Masukkan angka pada baris ke "<<x<<" kolom ke "<<y<<" : "; cin>>n[x][y]; } cout<<endl; } for(x=0;x<=2;x++) { for(y=0;y<=2;y++) { cout<<n[x][y]<<" "; } cout<<endl; } getch(); }

c++ array 1 dimensi


#include<constream.h> void main() { int a[5]; int x,y; y=1; clrscr(); for (x=0;x<5;x++) { cout<< Input Angka << : ;cin>>x; } for (x=0;x<5;x++) { cout<<\n Hasil : ;cout<<x; } getch(); }

You might also like