Tuesday, 28 February 2017

How to use Java Code Example for Try-Catch Function to Get Exception Error

//**************************Start***************************

import java.util.*;

/**
 *
 * @author HP
 */
public class try_catch {

    public static void main(String args[]) {
        int i, j;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter any 2 no.");
        i = sc.nextInt();
        j = sc.nextInt();
        try {
            int result = i / j;
            System.out.println("Result= " + result);
        }

        catch (Exception es) {
            System.err.println(es.getMessage());
        }
    }
}


//**************************End***************************

No comments:

Post a Comment

Welcome, happy learning

Charactor_At_Position

public class Char_At_Position { public static void main(String[] args) { String str = "Wankhede"; String rev=""...