Javatpoint Logo
Javatpoint Logo

Java Long compare() Method

The compare() method of Java Long class is used to compare two long objects numerically.

Syntax:

Parameter:

The above method consists of two parameters:

  1. The first long value that needs to be compared.
  2. The second long value that needs to be compared.

Return:

The above method returns:

  1. 0 if x==y.
  2. A value less than 0 if x<y.
  3. A value greater than 0 if x>y.

Example 1

Test it Now

Output:

The value '76' is greater than 42

Example 2

Output:

Enter your valid age: 35
You are eligible to vote.

Example 3

Output:

Enter your birth year : 2020
PLEASE enter a valid birth year.
Next TopicJava Long





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA