# Precedence rules

Posted by HTC
Announcements Last Post
: Programming Students at UNISA School of Computing 06/19/2019 02:01PM
SoC Curricula 09/30/2017 01:08PM
Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
School of Computing Short Learning Programmes 11/24/2014 08:37AM
Unisa contact information 07/28/2011 01:28PM
 Precedence rules October 11, 2010 10:02PM Registered: 9 years ago Posts: 16 Rating: 0
Assignment 1 question 7 refers.

How does the lecturer get 6?

 Re: Precedence rules October 12, 2010 06:56AM Admin Registered: 14 years ago Posts: 9,714 Rating: 309
This is straight from the solution?

What is the result of the following expression using the precedence rules in Java?
4-2*3/6%2
1. 1
2. 4
3. 3
4. -1
Solution: 3
 Re: Precedence rules October 14, 2010 02:37PM Registered: 9 years ago Posts: 16 Rating: 0
Hi Doc,

I don`t get it
.. working from left to right the equation becomes
4-(((2*3)/6)%2)
4-((6/6)%2)
4-(1%2)
? 1%2 is 0.5?
4-.5
=3.5?

from assignment1 question 7
6-2*(5+2)%2
6-((2*7)%2)
6-0
6

is my reasoning in line with JAVA lingo?
 Re: Precedence rules October 15, 2010 07:36AM Admin Registered: 14 years ago Posts: 9,714 Rating: 309
4-(1%2)
Think in terms of long division as you did in school

2 goes into 1 how many times? 0 times. What remains? 1.
Thus it is 4-1 = 3
Sorry, only registered users may post in this forum.