Win a copy of Design for the Mind this week in the Design forum!

# ArithmeticException

dolly shah
Ranch Hand
Posts: 383
Please select arithmetic operations which can result in ArithmeticException

Division: /
Modulo: %
Subtraction:-

I think the answer is Division & Modulo. Can any one please help me?

Lucky J Verma
Ranch Hand
Posts: 278
Yaa ,i also think asnwer is Division.
Hows is modulo?
What is source of this Question.

Vikrant Sahdev
Ranch Hand
Posts: 58
Only Division & Modulo returns Arithmetic Exception and that too for int/ long.

Burkhard Hassel
Ranch Hand
Posts: 1274
int something = 3; // or 0...
System.out.println(17 % something);
What happens when you calculate 17 modulo something?
First 17 is divided by something, and then the remainder is returned.
When you calc. x % 0...

Bu.
[ September 07, 2007: Message edited by: Burkhard Hassel ]

dolly shah
Ranch Hand
Posts: 383
Hi Hassel,
So I was right. Division & modulo are the answers. Or Was I wrong?

Burkhard Hassel
Ranch Hand
Posts: 1274
No.

Onkar Joshi
Ranch Hand
Posts: 116
Originally posted by dolly shah:
Hi Hassel,
So I was right. Division & modulo are the answers. Or Was I wrong?

You are correct.

Read section 15.6 here for details : http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html

dolly shah
Ranch Hand
Posts: 383
Hi Hassel,
No means I was wrong or right?

Vikrant Sahdev
Ranch Hand
Posts: 58
Yes, you are correct

Burkhard Hassel
Ranch Hand
Posts: 1274
question was: Or Was I wrong?

Means you were not wrong.
Bu.

Mack Stevens
Greenhorn
Posts: 17
Hi............................
Try this interesting code,it will add to your knowledge.
code:
class FloatExample
{
public static void main(String ar[])
{
System.out.println(2.0/0);
}
}

Burkhard Hassel
Ranch Hand
Posts: 1274
or System.out.println(-3D/0);