Life long sharing . . .

Java – Basic Operations

Posted on: November 23, 2015

This website has a comprehensive list of Java operations: http://www.tutorialspoint.com/java/java_basic_operators.htm.

Here are some of the frequently used one.

Lesson5-note1

Lesson5-note2

Let’s do some quick exercise.

Lesson5-code1

What do you think is the output of the above codes?

Lesson5-note3

Let’s try this code. Can you first guess the output?

Lesson5-code2

Lesson5-note4

Lesson5-note6

Try to understand this code:
Lesson5-code3

Now, can you add a String variable called color, and assign the value of “red” if (a is less than 5 and b is more than 20), and “blue” if (a is greater or equal to 10 or b is equal to 30). Add this line of code in line 8 and line 11. You then add a System.out.println code to display the value of color.

What is the output?

Lesson5-note7

This may seem a little hard for you now, but we will revisit this again.

Lesson5-code4

Advertisements

1 Response to "Java – Basic Operations"

1. a == b = false
a != b = true
a > b = false
a = a = true
b <= a = false
c = 6
2. a && b = false
a || b = true
!(a && b) = true
3. Value of b is : 30
Value of b is : 20
4. blue

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives

November 2015
M T W T F S S
« Oct   Dec »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 181 other followers

%d bloggers like this: