Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArithmeticException

 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please select arithmetic operations which can result in ArithmeticException

Multiplication: * -answer
Division: /
Modulo: %
Addition: +
Subtraction:-

I think the answer is Division & Modulo. Can any one please help me?
 
Lucky J Verma
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yaa ,i also think asnwer is Division.
Hows is modulo?
What is source of this Question.
 
Vikrant Sahdev
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only Division & Modulo returns Arithmetic Exception and that too for int/ long.
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hassel,
So I was right. Division & modulo are the answers. Or Was I wrong?
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.
 
Onkar Joshi
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hassel,
No means I was wrong or right?
 
Vikrant Sahdev
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are correct
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
question was: Or Was I wrong?
answer was: No.


Means you were not wrong.
Bu.
 
Mack Stevens
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or System.out.println(-3D/0);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic