Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-exception Example to show double exception in java

Related Tutorials


 
 

Share on Google+Share on Google+

Example to show double exception in java

Advertisement
The Tutorial describe you a code from double exception in java.

Example to show double exception in java

     

The Tutorial describe you a code from double exception in java. The given below program tells about the occurrence of double exception. Double is a class that wraps a value of the primitive type double in an object. Double exception occurs in java when the string or primitive data type are not converted into a double value. The step involved in a program are described below - 

1)We have a class Double Exception, that include a main method. The main method include  -

Buffered Reader-  This read the text from the character stream

read line  ( ) - This is used to read a line of text.

to string( )  - This object  return you a string irrespective of any type of data type.

In case a user try to enter a string or primitive data type, that is not converted into a double, this causes the try block to cause exception in a code The exception subsequently handled by a catch block and show you a user defined message in the println.

Doubleexception.java


import java.lang.Math.*;

public class Doubleexception {

  public static void main(String args[]) {
  double c = 0;
  try {
  Double d = (500 100.9;
  c = d.intValue();
  catch (Exception e) {
  System.out.println(e.getMessage());
  }
  System.out.println("Value of c is: "+c);
  }
}

Output of the program

Value of c is: 4.0

Note:-if you will pass any number other than double type program will generate exception.

Download sourcr code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 12, 2009

Related Tutorials

Discuss: Example to show double exception in java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
ganesh
June 6, 2012
double exception in java

In this program's result to be execute without any error. I need answer What kind of error will come in this exception.
DMCA.com