programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Jeanne Boyarsky
• Tim Cooke
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Carey Brown
• Frits Walraven
Bartenders:
• Piet Souris
• Himai Minh

# Arithmetic Operators

Ranch Hand
Posts: 68
• Number of slices to send:
Optional 'thank-you' note:
class testing{
public static void main(String args[]){
int i = 3/3*6/2*6-1;
System.out.println(i);
}
}

In the above class , How should I evaluate this expression

int i = 3/3*6/2*6-1;

Greenhorn
Posts: 20
• Number of slices to send:
Optional 'thank-you' note:
int i = 3/3*6/2*6-1;

* and / - have same priority

3/3 = 1
than
(3/3)*6 = 6
than
((3/3)*6)/2 = 3
than
(((3/3)*6)/2)*6 = 18
than
((((3/3)*6)/2)*6) - 1 = 17

susan waters
Ranch Hand
Posts: 68
• Number of slices to send:
Optional 'thank-you' note:
thanks for the reply. So it starts evaluate from left to right ? then priority between + - and * / ? thanks

Ranch Hand
Posts: 66
• Number of slices to send:
Optional 'thank-you' note:
* and / have higher priority over + -. Within the group they are evaluated from left to right.

In the expression, - has lowest priority and separates the group into two:

[({(3/3)*6}/2)*6] minus 1

everything else has some priority and is evaluated from left to right.

susan waters
Ranch Hand
Posts: 68
• Number of slices to send:
Optional 'thank-you' note:
thanks. I understand now.