Try Catch Exception di Java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package ifelsename;

/**
*
* @author komp19
*/
public class ifElseName {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
char firstInitial = ‘a’;
System.out.println(“Masukkan huruf awal nama Anda :”);
try {
firstInitial = (char)System.in.read();
} catch (Exception e){
System.out.println(“Error: ” + e.toString());
}

if(firstInitial == ‘a’)
System.out.println(“Nama anda pasti Asep!”);
else if(firstInitial == ‘b’)
System.out.println(“Nama anda pasti Brodin!”);
else if(firstInitial == ‘c’)
System.out.println(“Nama anda pasti Cecep!”);
else
System.out.println(“Nama anda tidak dikenal!”);

}
}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google

You are commenting using your Google account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s