> > If-Else Multi Kondisi

If-Else Multi Kondisi

Untuk If-Else Multi Kondisi(kondisi 1 & kondisi 2), maka diperlukan operator LOGIKA "&&" untuk relasi AND, dan operator LOGIKA "||" untuk relasi OR

import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class If_Else_Multi_Kondisi {
public static void main (String[] args){

InputStreamReader input = new InputStreamReader(System.in);
BufferedReader buf = new BufferedReader(input);

try{
System.out.println("Masukkan nilai Anda !");
String strNilai = buf.readLine();
int nilai = Integer.parseInt(strNilai);

if ((nilai>=80)&&(nilai<=100)) //Kondisi 1 (nilai>=80), dan kondisi 2 (nilai<=100)
System.out.println("Nilai Anda "+nilai+"\nDengan grade A");
else if ((nilai>=71)&&(nilai<=79))
System.out.println("Nilai Anda "+nilai+"\nDengan grade B+");
else if ((nilai>=65)&&(nilai<=70))
System.out.println("Nilai Anda "+nilai+"\nDengan grade B");
else if ((nilai>=61)&&(nilai<=64))
System.out.println("Nilai Anda "+nilai+"\nDengan grade C+");
else if ((nilai>=56)&&(nilai<=60))
System.out.println("Nilai Anda "+nilai+"\nDengan grade C");
else if ((nilai>=40)&&(nilai<=55))
System.out.println("Nilai Anda "+nilai+"\nDengan grade D");
else if((nilai>=0)&&(nilai<=39))
System.out.println("Nilai Anda "+nilai+"\nDengan grade E");
}
catch(Exception e){
System.out.println("Kesalahan Dalam Pengisian Nilai");
}
}
}

Leave a Reply

Powered by Blogger.