# Thread: How do i solve a java precedence PLEEEASE HELP ME :(

1. Member
Join Date
Jul 2013
Posts
1
Rep Power
0

## How do i solve a java precedence PLEEEASE HELP ME :(

hi ...

i need someone to help to a problem..

4+3*2/3-7*3+15%2*7/2+1

2. Senior Member
Join Date
Apr 2013
Location
Sweden
Posts
220
Rep Power
1

## Re: How do i solve a java precedence PLEEEASE HELP ME :(

use parentheses?

3. ## Re: How do i solve a java precedence PLEEEASE HELP ME :(

What do you mean, "solve" it?

4. Senior Member
Join Date
Jan 2013
Location
United States
Posts
2,735
Rep Power
4

## Re: How do i solve a java precedence PLEEEASE HELP ME :(

What does your book say (you are using a book, right?)

Regards,
Jim

5. ## Re: How do i solve a java precedence PLEEEASE HELP ME :(

Read one of my blog articles (see the link near the top-right of this reply); the article discusses a fairly complete expression parser and several evaluators (all code is included). You can also do it the lazy way and let the embedded Javascript engine do the nitty-gritty work.

kind regards,

Jos

6. Member
Join Date
Jul 2013
Posts
2
Rep Power
0

## Re: How do i solve a java precedence PLEEEASE HELP ME :(

one acronym: BODMAS

1. Brackets
2. Of
3. Divide
4. Multiplication
6. Subtration

Precedence indicated by the numbers

7. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
2,673
Rep Power
3

## Re: How do i solve a java precedence PLEEEASE HELP ME :(

2 = Orders, not of.

8. Member
Join Date
Jan 2012
Posts
12
Rep Power
0

## Re: How do i solve a java precedence PLEEEASE HELP ME :(

@YoHeHo :
Use the BODMAS principle
I think your equation can be re write to this form ::

4+(3*(2/3))-(7*3)+((15/2)*(7/2))+1

I wrote a java code for you, i also didn't understand what do you mean by the word "solve" here
Java Code:
```import java.io.*;
class operation
{
public static void main(String args[])
{
float a=4+(3*(2/3))-(7*3)+((15/2)*(7/2))+1;

System.out.println("Result : "+a);
}
}```

9. ## Re: How do i solve a java precedence PLEEEASE HELP ME :(

Originally Posted by javaBee
Java Code:
```import java.io.*;
class operation
{
public static void main(String args[])
{
float a=4+(3*(2/3))-(7*3)+((15/2)*(7/2))+1;

System.out.println("Result : "+a);
}
}```

Jos

10. Senior Member
Join Date
Jan 2013
Location
United States
Posts
2,735
Rep Power
4

## Re: How do i solve a java precedence PLEEEASE HELP ME :(

The BODMAS principle doesn't apply to Java. For example, division and multiplication have the same precedence so they then evaluate from left to right in the absence of parens.

int a = 2/3*3; // evaluates to 0
int b = 3*2/3; // evaluates to 2

Regards,
Jim

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•