Soal :
Menggunakan Inputan (Scanner)
dengan ketentuan
nilai>60 Nilai>=0 Grade="E"
ket : lulus Nilai>=59 Grade="D"
else Nilai>=70 Grade="C"
ket : Nilai>=80 Grade="B"
gagal Nilai>=90 Grade="A"
Jawab :
Import java.util.Scanner; //Import java untuk fungsi meminta inputan
public class if_scanner_1 {
public static void main (String [] args){
Scanner input = new Scanner (System.in);
int nilai;
System.out.print("Masukkan nilai ujian (0-100):");
nilai = input.nextInt();
if (nilai>=60){
System.out.print("Lulus");
if(nilai>=90)
System.out.print("Grade=A");
else if (nilai>=80)
System.out.print("Grade=B");
else if (nilai>=70)
System.out.print("Grade=C");
else if (nilai>=59)
System.out.print("Grade=D");
else
System.out.println("Grade=E");
} else if (nilai < 60 ){
System.out.println ("Tidak lulus");
if (nilai>=59)
System.out.println("Grade=C");
else
System.out.println ("Grade=E");
} else
System.out.print("Inputan yang anda masukkan salah"); {untuk menghindari program error}
}
}
0 komentar:
Posting Komentar