Exception error (i)

Source: Internet
Author: User
public class Divide throws Divideexception,  arithmeticexception{  //error throws should be private int in method instead of class
	
	Numerator,denominator;
	
	public Divide (int num, int denom)
	{
		numerator = num;
		denominator = denom;
	}
	
	Public String toString () 
	{
		if (Denominator < 0)
			throw new Divideexception ("the denominator can not less t Han Zero ");
		
		Return String.Format ("%s", numerator/denominator);
	}
	
	

public class Divide {  
	
	private int numerator,denominator;
	
	public Divide (int num, int denom)
	{
		numerator = num;
		denominator = denom;
	}
	
	Public String ToString throws Divideexception,  arithmeticexception ()  
	  /**
	   * ERROR One: Overwrite (override) ToString method You cannot throw an error because the error is not thrown in object ...
	   * ERROR Two: The parentheses in ArithmeticException () should be followed by the method (ToString ()) throws ....
	   * *
	{
		if (Denominator < 0)
			throw new Divideexception ("the denominator can not less than zero");
		
		Return String.Format ("%s", numerator/denominator);
	}
	
	

public class Divide {  
	
	private int numerator,denominator;
	
	public Divide (int num, int denom)
	{
		numerator = num;
		denominator = denom;
	}
	
	Public String ostring () throws Divideexception,  arithmeticexception 
	  /**
	   * Fixed error to change ToString to ostring
	   * 
	   *
		/{if (Denominator < 0)
			throw new Divideexception ("the denominator can not less than zero"); C15/>return String.Format ("%s", numerator/denominator);
	}
	
	


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.