Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: what is the way to Calculate

1. ## what is the way to Calculate

public class NewClass4 {
public static void main(String[] args) {
int a = 1;
int b = 2;
int c = 3;
a += 5;
b *= 4;
c += a * b;
c %= 6;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);

2. ## Re: what is the way to Calculate

Do you have any specific questions about the code?

[code=java]
[/code]
to get highlighting and preserve formatting.

3. ## Re: what is the way to Calculate

How does c = 3?

For clarity, rewrite the code without using shorthand (augmented operators).
```		int a = 1;
int b = 2;
int c = 3;
a = a + 5;
b = b * 4;
c = c + a * b;
c = c % 6;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);```
Then trace values of all the variables on some paper.

When you get to c = c + a * b; note that multiplication, division, and remainder operators are applied first.
This means a*b is evaluated first and then added to c.

4. ## Re: what is the way to Calculate

ok but how i do it a*b is 2 and then how do i do c=c&6

5. ## Re: what is the way to Calculate

The % sign means divide the two numbers and give us only the remainder.

6. ## Re: what is the way to Calculate

so what the result of c = c + a * b;

--- Update ---

what the result of c = c + a * b;

7. ## Re: what is the way to Calculate

Do you have a PC and a java compiler? Write a small program with that statement in it, compile it and execute it.
Make sure the values of the variables are not the same and are greater than 1.

8. ## Re: what is the way to Calculate

hi

well if we trace the code then
a = 1+5 =6;
b = 2*4 = 8;
c = 3 + 48 =51;
c = 51%6 = 3 (since dividing 51 by 6 gives remainder 3)