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

How dbms is better to use than flat-file database, How can you justify that...

How can you justify that a DBMS is better to use than Flat-file database? A DBMS takes care of the storage, retrieval, and management of large data sets on a Database. It give

Program for solving the producer consumer problem, For this assignment we w...

For this assignment we will be solving the producer-consumer problem with a bounded buffer. You are required to implement this assignment in Java. There are three components in thi

Starting in new app, iam trying to build an application that store informat...

iam trying to build an application that store information like name mobile age in a file its like a registration form everytime i enter a new person data i want the applicaion mak

How to creating arrays in java, How to Creating Arrays in java? Declari...

How to Creating Arrays in java? Declaring arrays merely says what type of values the array will hold. It does not form them. Java arrays are objects, and such as any other obje

Explain what is multilevel inheritance, Explain what is Multilevel Inherita...

Explain what is Multilevel Inheritance ? The Car-Motorcycle-MotorVehicle instances showed single-level inheritance. There's nothing to stop you from going next. You can describ

Eclipse javaj, how to write coding for money and currency

how to write coding for money and currency

Want an android app to be build, Want an Android App to be Build What i ...

Want an Android App to be Build What i want is a Taxi App for Android and if good price for iOS too. The App want to have a Website where to add Cars whit all information and

Package in java? , It helps to resolve naming conflicts when different pack...

It helps to resolve naming conflicts when different packages have classes with the same names. This also helps you prepare files within your project. As define : java.io package

How to prepare trial balnce reports, i m working on an accounting software ...

i m working on an accounting software and need the java code for preparing trial balance report

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