Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!

A Ka

Greenhorn
+ Follow
since Mar 17, 2014
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
5
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by A Ka

Thanks, I sorted out the problem,
values are int1=10, int2=20, int3=30

Jesper de Jong wrote:What exactly is your question?

You can find a table that shows the precedence of operators in Oracle's Java Tutorials: Operators. As you can see in the table, % has the same precedence as multiplication * and division /. Expressions are evaluated from left to right, so if you have an expression with multiple operators that have the same precedence, then the one on the left will be evaluated first.

So a line such as: int1 % int2 * (int3 + int1) / int2

will be interpreted as: ((int1 % int2) * (int 3 + int1)) / int2

Note that you didn't tell us what the values of the variables int1, int2, int3 is so we can't explain you with those values what exactly happens.

4 years ago
very simple question, can you please open my eyes for below, I guess it should be 10%40 for row below, where I'm wrong?

System.out.println(int1%int2*(int3+int1)/int2);
System.out.println(10%40);

20
10
4 years ago
I see both variants work, meaning of += is clear.
for me it's not clear the meaning of this code below. Does compiler ignore + sign?
because other variants like val4=*3 or val4=/3 don't work


3
4 years ago
Please explain why there is no value in output for below code

4 years ago

Joanne Neal wrote:

A Ka wrote: Why I cannot use 2 public classes like below?


Because that's how Java was designed. All public top-level classes have to be in a file that matches the name of the class plus a .java extension.
So your two classes need to be in files called Hello.java and Welcomer.java.



Thanks,
I've modified the code to the below and it works. Is there other ways to use that 2 classes in one file?

4 years ago
Hi,

Can you please help me to sort out some doubts for the below code? Why I cannot use 2 public classes like below?



Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The public type Welcomer must be defined in its own file

at Welcomer.<init>(Hello.java:9)
at Hello.main(Hello.java:5)
4 years ago
Hi,
Can you show me some exaples like below to understand this topic much better? What are the benefits of using static variable as we can refer to created object emp1.bankid, not class itself Emp.bankid



run:
test
11
5





run:
test
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static variable bankid cannot be referenced from a static context
at test.Person.main(Person.java:23)
Java Result: 1


run:
test
22
22
5
4 years ago
Can somebody please explain me the difference below?


run:
test
0



run:
test
11
4 years ago

Henry Wong wrote:

A Ka wrote:
oh, my bad. sorry. was a hard working day



No worries... And BTW, welcome to the ranch !!

Henry



Thank you. This forum is awesome!
4 years ago

Henry Wong wrote:

A Ka wrote:Core Java Fundamentals book by Horstman, page 48.
It is said that there is a difference between ++m and m++ but as you see the result below, both a=b=16.
How is wrong?

book



run:
a=16
b=16



Did you noticed that in your example, you incremented m twice -- and didn't increment n at all? Do you think that it could be related to that? ... and BTW, sometimes, in order to see a difference, you have to try out more than one example.

Henry


oh, my bad. sorry. was a hard working day
4 years ago
Core Java Fundamentals book by Horstman, page 48.
It is said that there is a difference between ++m and m++ but as you see the result below, both a=b=16.
How is wrong?

book



run:
a=16
b=16
4 years ago
simple code



why variable is a=6 and not 10 in the last 2 lines?
Is it possible to reset variable a as it was declared a=10?

run:
test
10
9
8
7
6
1006
4 years ago