0% found this document useful (0 votes)
43 views2 pages

Tugas Array

The Java program collects and displays student names, subjects, and their corresponding grades. It prompts the user to input the number of students and subjects, then gathers names and grades, and finally outputs a table of grades along with the average grades for each subject. The program utilizes arrays to store and manage the data efficiently.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views2 pages

Tugas Array

The Java program collects and displays student names, subjects, and their corresponding grades. It prompts the user to input the number of students and subjects, then gathers names and grades, and finally outputs a table of grades along with the average grades for each subject. The program utilizes arrays to store and manage the data efficiently.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package tugasarray;

import java.util.Scanner;

public class TugasArray {


public static void main(String[] args)
{

output cmp = new output();


System.out.println(cmp.hd1);
System.out.println(cmp.hd2);
System.out.println(cmp.hd3);
System.out.println(cmp.hd4);
input gb = new input();
int jmlmrd = gb.jmlmurid();
int jmlpljrn = gb.jmlpelajaran();
String[] namapelajaran = new String[jmlpljrn];
String[] namamurid = new String[jmlmrd];
Scanner h = new Scanner(System.in);
int[][] nilai = new int[jmlmrd][jmlpljrn];

for (int i=0; i<jmlmrd; i++)


{
System.out.print("Masukan Nama Murid ["+i+"]= ");
namamurid[i]= h.next();
}

for (int j=0; j<jmlpljrn; j++)


{
System.out.print("Masukan Nama Mata Pelajaran ["+j+"]= ");
namapelajaran[j]= h.next();
}

for(int i=0; i<jmlmrd; i++)


{
for(int j=0; j<jmlpljrn; j++)
{
System.out.print("Masukkan Nilai Pelajaran "+namapelajaran[j]+"
"+namamurid[i]+ " = ");
nilai[i][j] = h.nextInt();
}
}

System.out.println("");
System.out.print("Nama");

for(int i=0; i<jmlpljrn; i++)


{
System.out.print("\tNilai "+namapelajaran[i]);
}

System.out.println();

for(int i=0; i<jmlmrd; i++)


{
System.out.print(namamurid[i]);

for(int j=0; j<jmlpljrn; j++)


{
System.out.print("\t\t"+nilai[i][j]);
}

System.out.println(" ");
}

System.out.print("Rata2");

for(int i=0; i<jmlpljrn; i++)


{
float total=0;
for(int j=0; j<jmlmrd; j++){
total +=nilai[j][i];
}
System.out.print("\t\t"+total/jmlmrd);
total=0;
}

System.out.println("");

}
}

You might also like