answersLogoWhite

0


Best Answer

One possible way (although much less efficient than using the operators directly) is by using BigInteger:

int a = 5, b = 7;

int sum = BigInteger.valueOf(a).add(BigInteger.valueOf(b)).intValue();

However, BigInteger.add() might use arithmetic operators in its own calculations; they are simply hidden from the programmer's view.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

class Comparing{

public static void main(String[] args)

{

int a=24, b=25;

if (a == b)

{

System.out.println("Both are equal");

}

else if(a>b)

{

System.out.println("a is greater than b");

}

else {

System.out.println("b is greater than a");

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

If the values are of the basic types (integer, etc.), any of the standard expression operators can be used (but be aware there is a huge difference between the assignment operator '=' and the comparison operator '=='.) For objects, only those operators defined within the class via operator overloading methods are usable.

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

The operator for equality is:==

Please note that a single equal sign is an assignment, not a comparison.

There are also operators to compare for greater than, greater than or equal, less than, less than or equal, and not equal.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

ds

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What operator can be used to compare 2 values in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the restriction that are applied to operator overloading?

Java does not support user defined operator overloading.The operator '+' is overloaded in Java and can be used for adding both numbers and Strings.


What does the modulus operator in Java do?

It is an binary arithmetic operator which returns the remainder of division operation. It can used in both floating-point values and integer values. opLeft % opRight where, opLeft is the left operand and opRight is the right operand. This expression is equivalent to the expression opLeft - ((int) (opLeft / opRight) * opRight)


What is a operator overriding in java?

Java does not support object overriding. It does support operator overloading by means of the "+" symbol which is used for both numeric addition as well as string concatenation.


Why are you used new operator in main method in java?

new is used for memory allocation in java which on later automatically deallocated by garbage collector.


How do you campaire Strings in java?

String class in Java has an 'equals' method that can be used to compare strings.


Which operator is used to compare strings in Perl?

eq


What type of operator is used to compare two values?

Conditional operators are used to compare two values. The result of a comparison is either true or false. Boolean data types can hold the values true or false. Here's a list of operators. = Equal to > Greater than < Less than >= Grater than or equal to <= Less than or equal to <> Not equal to


What is different between equals equals and equals method in java?

== (the double equal sign) is used to compare two values (resulting in true if they are equal, false otherwise). = (a single equal sign) is used to assign a value to a variable.


What is a Java scanner used for?

A Java Scanner is used for reading and producing several types of computer values. Using Java Scanners helps one easily read user input. There is a free course one might take to get better acquainted with Java Scanners provided by Java.


Complex assignment in java?

An Assignment operator in Java is the operator that is used to assign a variable a value. if you declare int x = 10; then the value 10 is assigned to the variable x. here the "=" symbol is the assignment operator.


What does equals equals mean in java?

operator to compare two objects. The simple "=" sign is used for assignment - assigning a value to a variable. Here are examples of the two: x = 15; // Assign the value 15 to the variable if (x == 10) ... // Compare variable "x" with some value


What is use of new operator is it necessary to be used when object of the class is crated why?

In the case of the Java language, it is necessary. The reason is because that's how creating objects was defined in Java. Note that a method can return an object, so the use of the "new" operator may be hidden: x = SomeClass.someMethod(); In this example, is someMethod() returns an object, x will point to this object; however, the "new" operator is still used in the method someMethod().