Menghitung Nilai MHS dan Pengulangan
public class Baru {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
garis();
System.out.println(" MENU PILIHAN ");
garis();
System.out.println("1. Menhitung Nilai Mahasiswa");
System.out.println("");
System.out.println("2. Exit");
garis();
System.out.println("");
System.out.print("Anda pilih no :");
int pilih=input.nextInt();
switch(pilih){
case 1:{
int[] npm=new int[20];
String[] nama=new String[20];
String[] jur=new String[20];
String[] mk=new String[20];
int[] n_tgas=new int[20];
int[] n_uts=new int[20];
int[] n_uas=new int[20];
garis();
System.out.println(" MENGHITUNG NILAI MAHASISWA");
garis();
System.out.println("");
System.out.print("Masukan jumlah data ="); int n=input.nextInt();
for(int i=1;i<=n;i++){
System.out.println("Data ke"+i +":");
System.out.print("NPM :"); npm[i]=input.nextInt();
System.out.print("Nama :"); nama[i]=input.next();
System.out.print("Jurusan :"); jur[i]=input.next();
System.out.print("Mata Kuliah :"); mk[i]=input.next();
System.out.print("Nilai tugas :"); n_tgas[i]=input.nextInt();
System.out.print("Nilai UTS :"); n_uts[i]=input.nextInt();
System.out.print("Nilai UAS :"); n_uas[i]=input.nextInt();
double rata=(n_tgas[i]+n_uts[i]+n_uas[i])/3;
System.out.println("Nilai rata-rata ="+rata);
}
break;
}
default:System.exit(0);
}
}
static void garis(){
System.out.println("==========================================");
}
}
Outputnya :
run:
==========================================
MENU PILIHAN
==========================================
1. Menhitung Nilai Mahasiswa
2. Exit
==========================================
Anda pilih no :1
==========================================
MENGHITUNG NILAI MAHASISWA
==========================================
Masukan jumlah data =2
Data ke1:
NPM :432
Nama :ajeng
Jurusan :ti
Mata Kuliah :pm2
Nilai tugas :80
Nilai UTS :70
Nilai UAS :87
Nilai rata-rata =79.0
Data ke2:
NPM :434
Nama :ina
Jurusan :ti
Mata Kuliah :pm1
Nilai tugas :70
Nilai UTS :80
Nilai UAS :70
Nilai rata-rata =73.0
BUILD SUCCESSFUL (total time: 1 minute 22 seconds)
public class Hitung {
public static void main(String[] args){
int[] data1={0,1,2,3,4,5};
int[] data2={0,1,2,3,4,5};
int i,j,jum;
System.out.println("+ 0 1 2 3 4 5");
System.out.println("-----------------");
for (i=0;i<=5;i++){
System.out.print(i);
for(j=0;j<=5;j++){
jum=data1[i]+data2[j];
System.out.print(" "+jum);
}
System.out.println("");
}
}
}
Outputnya adalah :
run:
+ 0 1 2 3 4 5
-----------------
0 0 1 2 3 4 5
1 1 2 3 4 5 6
2 2 3 4 5 6 7
3 3 4 5 6 7 8
4 4 5 6 7 8 9
5 5 6 7 8 9 10
BUILD SUCCESSFUL (total time: 6 seconds)
Tidak ada komentar:
Posting Komentar