hi ...

i need someone to help to a problem..

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

how could i solve this and what should i do first... please help me :[

Printable View

- 07-12-2013, 02:07 AMYoHeHoHow 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

how could i solve this and what should i do first... please help me :[ - 07-12-2013, 02:29 AMsuperhaNdsRe: How do i solve a java precedence PLEEEASE HELP ME :(
use parentheses?

- 07-12-2013, 04:22 AMkjkrumRe: How do i solve a java precedence PLEEEASE HELP ME :(
What do you mean, "solve" it?

- 07-12-2013, 05:01 AMjim829Re: How do i solve a java precedence PLEEEASE HELP ME :(
What does your book say (you are using a book, right?)

Regards,

Jim - 07-12-2013, 10:26 AMJosAHRe: 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 - 07-12-2013, 10:47 AMkhairulRe: How do i solve a java precedence PLEEEASE HELP ME :(
one acronym: BODMAS

1. Brackets

2. Of

3. Divide

4. Multiplication

5. Addition

6. Subtration

Precedence indicated by the numbers - 07-12-2013, 11:12 AMgimbal2Re: How do i solve a java precedence PLEEEASE HELP ME :(
2 = Orders, not of.

- 07-12-2013, 12:57 PMjavaBeeRe: How do i solve a java precedence PLEEEASE HELP ME :(
@YoHeHo :

Quote:

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

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);

}

}

- 07-12-2013, 01:18 PMJosAHRe: How do i solve a java precedence PLEEEASE HELP ME :(
- 07-12-2013, 07:51 PMjim829Re: 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