Contoh Soal Java Menggunakan Nested IF
Soal:
Buat Class If klsmhs
Buat Class If klsmhs
var; grade tipe data char
Nim; String
Nama; String
Nilai absen,nilai tugas,nilai uts, nilai uas, nilai akhir; double
Isikan nama dan nim masing2...
Rumus = nilai akhir = (0,3*nilaiuts)+(0.4*nilaiuas)+(0.2*nilaitugas)+(0.1*nilaiabsen)
Kondisi jika nilaiakhir >=80,grade=A
>=70,grade=B
>=50,grade=C
>=30,grade=D, selain itu E
** * @(#)KelasMahasiswa.java * * */ import java.io.*; public class KelasMahasiswa { public static void main (String args []) throws Exception { char grade; String nim, nama; double absen, tugas, uts, uas, akhir; BufferedReader inputan = new BufferedReader (new InputStreamReader(System.in)); System.out.print("Isikan Nama Anda : "); nama = inputan.readLine(); System.out.print("Isikan Nim Anda : "); nim = inputan.readLine(); System.out.print("Masukkan Nilai Absen : "); absen = Integer.parseInt(inputan.readLine()); System.out.print("Masukkan Nilai Tugas : "); tugas = Integer.parseInt(inputan.readLine()); System.out.print("Masukkan Nilai UTS : "); uts = Integer.parseInt(inputan.readLine()); System.out.print("Masukkan Nilai UAS : "); uas = Integer.parseInt(inputan.readLine()); akhir = (0.1*absen)+(0.2*tugas)+(0.3*uts)+(0.4*uas); System.out.println("Nilai Akhir : " + akhir); if (akhir >= 80){ System.out.println("\nGrade : A"); } else if (akhir >= 70){ System.out.println("\nGrade : B"); } else if (akhir >= 50){ System.out.println("\nGrade : C"); } else if (akhir >= 30){ System.out.println("\nGrade : D"); } else { System.out.println("\nGrade : E"); } } }
No comments:
Post a Comment