Skip to main content

Posts

Showing posts from February, 2021

Java Creating Custom Exception With Examples And Best Practices

Custom Checked and Unchecked Exception in Java with Examples  Custom checked and unchecked exception in java What is Exception Handling? Exception is unwanted event that interrupts the normal flow of program. When Exception is occurs during program execution it gets terminated. Learn more in details about Exception and how to handle Exception :- What is Exception and Exception handling in Java with examples   What is Custom Exception in Java? If we create our own Exception, then it is known as Custom Exception. Custom exception are also known as user-defined Exception, because it is defined by us. Why you need Custom Exception? You can provide your own exception message which can be easily understandable by client rather than java's exception message sometimes which may be hard to understand . If you need an exception type that isn't represented by those in the Java platform. If it help users if they could differentiate your exceptions from those thrown by classes written b...

Find Numbers with Even Number of Digits in Java | Programming Tutorial

Java Solution for Find Numbers with Even Number of Digits Given an array nums of integers, return how many of them contain an even number of digits.  Example 1 :- Input: nums = [12,345,2,6,7896] Output: 2 Explanation: 12 contains 2 digits (even number of digits).  345 contains 3 digits (odd number of digits).  2 contains 1 digit (odd number of digits).  6 contains 1 digit (odd number of digits).  7896 contains 4 digits (even number of digits).  Therefore only 12 and 7896 contain an even number of digits. Example 2 :- Input: nums = [555,901,482,1771] Output: 1 Explanation: Only 1771 contains an even number of digits. So lets see solution in Java :- Solution 1 :- import java.util.Scanner; public class FindNumberswithEvenNumberofDigits {     public static void main(String[] args) {                 Scanner sc = new Scanner(System.in);         System...