Describe the relational operators in java, JAVA Programming

Assignment Help:

Describe the relational operators in java?

Java has six relational operators which compare two numbers and return a boolean value. The relational operators are <, >, <=, >=, ==, and !=.

x < y

Less than

True if x is less than y, otherwise false.

x > y

Greater than

True if x is greater than y, otherwise false.

x <= y

Less than or equal to

True if x is less than or equal to y, otherwise false.

x >= y

Greater than or equal to

True if x is greater than or equal to y, otherwise false.

x == y

Equal

True if x equals y, otherwise false.

x != y

Not Equal

True if x is not equal to y, otherwise false.

Here are a few code snippets showing the relational operators.

boolean test1 = 1 < 2;  // True. One is less that two.
boolean test2 = 1 > 2;  // False. One is not greater than two.
boolean test3 = 3.5 != 1;  // True. One does not equal 3.5
boolean test4 = 17*3.5 >= 67.0 - 42; //True. 59.5 is greater than 5
boolean test5 = 9.8*54 <= 654; // True. 529.2 is less than 654
boolean test6 = 6*4 == 3*8; // True. 24 equals 24
boolean test7 = 6*4 <= 3*8; // True. 24 is less than or equal to 24
boolean test8 = 6*4 < 3*8; // False. 24 is not less than 24

This, thus, is an unusual use of booleans. Almost all use of booleans in practice comes within conditional statements and loop tests. You've already seen various examples of this. Earlier you saw this

if (args.length > 0) {
  System.out.println("Hello " + args[0]);
}

args.length > 0 is a boolean value. In other words it is either true or it is false. You could write

boolean test = args.length > 0;
if (test) {
  System.out.println("Hello " + args[0]);
}

instead. Therefore in easy situations such as this the original approach is customary. Similarly the condition test in a while loop is a boolean. When you write while (i < args.length) the i < args.length is a boolean.


Related Discussions:- Describe the relational operators in java

Indeed api integration and search bar fix, Indeed API integration and searc...

Indeed API integration and search bar fix (Java, Wordpress and PHP) I start a job portal on WP developed out of a customized template. We need an expert in integrating Indeed AP

What are the important methods of actionform, The significant methods of Ac...

The significant methods of ActionForm are: validate () & reset ().

Define the key weakness of the web, Define the key weakness of the web? ...

Define the key weakness of the web? the key weakness of the web is Initially web was designed only for humans to read not for computers to understand it.

Create sudoku in java, The SudCell Class A single cell in a Sudoku ...

The SudCell Class A single cell in a Sudoku must clearly represent a number from 1 to 9 .  But in a solver context, we need much more.  It isn't enough to say "this c

Loop statements, A loop is a set of commands which executes repeatedly till...

A loop is a set of commands which executes repeatedly till a denoted condition is met. JavaScript supports two loop statements: for & while. Additionally, you can employ the break

Describe the benefits of threads, Question 1: a) What is an "Operating...

Question 1: a) What is an "Operating System"? b) Describe the four main computer system components. c) Describe and compare "Parallel Systems" and "Distributed Systems

Write a cgi program, Write a CGI program in R, accessible through the class...

Write a CGI program in R, accessible through the class web server, that performs an analysis or creates a graph. You can provide a separate HTML page that displays the initial form

Student, short Java application that stores words in an Array or ArrayList....

short Java application that stores words in an Array or ArrayList.

Pebbles merchant, There is a pebble merchant. He sells the pebbles, that ar...

There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing that

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd