Welcome! Log In Create A New Profile

Advanced

Precedence rules

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

How does the lecturer get 6?

please advise
avatar
Mac
Re: Precedence rules
October 12, 2010 06:56AM
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
HTC
Re: Precedence rules
October 14, 2010 02:37PM
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?
avatar
Mac
Re: Precedence rules
October 15, 2010 07:36AM
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.

Click here to login