Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
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
Forum:
Programmer Certification (OCPJP)
Arithmetic Operators
susan waters
Ranch Hand
Posts: 68
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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;
Tahnks for the reply
Vladimir Scheglov
Greenhorn
Posts: 20
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks for the reply. So it starts evaluate from left to right ? then priority between + - and * / ? thanks
Anupama Ponnapalli
Ranch Hand
Posts: 66
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
* 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
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thanks. I understand now.
Something must be done about this. Let's start by reading this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Something i'm extremely confused on
operators
final
Loading 2-dimensional array with values
[solved]warning message:" Accessing static method numbers" #7th floor
More...