Program Java Array
Program Menghitung Nilai Siswa, Rata - rata, Lulus/Tidaknya Siswa
import java.util.Scanner;
public class multidimensi {
public static void main(String[] args) throws Exception {
Scanner input = new Scanner(System.in);
int mhs,jml, banyakTes = 4, nilai[][], ntt[], ntr[];
float rata[], jumlah[], rtt, rtr;
char grade;
String hasil;
System.out.print("Masukkan Jumlah Mahasiswa : ");
mhs = input.nextInt();
nilai = new int[mhs][banyakTes];
jumlah = new float[mhs];
rata = new float[mhs];
ntt = new int[banyakTes];
ntr = new int[banyakTes];
System.out.println();
for(int h=0;h<mhs;h++){
System.out.println("Mahasiswa " + (h+1));
for(int i=0;i<banyakTes;i++){
System.out.print("Nilai Tes " + (i+1) + " : ");
nilai[h][i] = input.nextInt();
jumlah[h] = jumlah[h] + nilai[h][i];
}
rata[h] = jumlah[h]/banyakTes;
System.out.println();
if(rata[h]>=80){
grade = 'A';
hasil = "Lulus";
}
else if(rata[h]>=70){
grade = 'B';
hasil = "Lulus";
}
else if(rata[h]>=55){
grade = 'C';
hasil = "Tidak Lulus";
}
else if(rata[h]>=45){
grade = 'D';
hasil = "Tidak Lulus";
}
else{
grade = 'E';
hasil = "Tidak Lulus";
}
System.out.println("Hasil Kelulusan Anda :"+hasil);
System.out.println("Anda Mendapatkan Grade:"+grade);
for(int i=0;i<banyakTes;i++){
ntt[i] = nilai[0][i];
ntr[i] = nilai[0][i];
}
}
rtt = rata[0];
rtr = rata[0];
for(int i=0;i<banyakTes;i++){
for(int j=0;j<mhs;j++){
if(ntt[i] < nilai[j][i]){
ntt[i] = nilai[j][i];
}
if(ntr[i] > nilai[j][i]){
ntr[i] = nilai[j][i];
}
}
}
for(int i=0;i<mhs;i++){
if(rtt < rata[i]){
rtt = rata[i];
}
if(rtr > rata[i]){
rtr = rata[i];
}
}
System.out.println("---------------------------");
System.out.println("Daftar Nilai Mahasiswa : ");
System.out.println("---------------------------");
System.out.println();
System.out.println("\t\tTest 1\tTest 2\tTest 3\tTest 4\tRata-rata");
for(int j=0;j<mhs;j++){
System.out.print("Mahasiswa " + (j+1));
for(int k=0;k<banyakTes;k++){
System.out.print("\t" + nilai[j][k]);
}
System.out.print("\t" + rata[j]);
System.out.println();
}
System.out.println();
System.out.print("Nilai Tertinggi\t");
for(int j=0;j<banyakTes;j++){
System.out.print(ntt[j] + "\t");
}
System.out.print(rtt);
System.out.println();
System.out.print("Nilai Teredah\t");
for(int j=0;j<banyakTes;j++){
System.out.print(ntr[j] + "\t");
}
System.out.print(rtr);
System.out.println();
}
}
Hasil Output
Komentar
Posting Komentar