Check if number is even without using if statement in java #interviewquestions #java4quicklearning

preview_player
Показать описание
Check if number is even without using if statement in java #interviewquestions #java4quicklearning

how to check if a number is odd or even in java,even number,java,even number using if statement,java program to number is even or odd using if ..else statement,check number is odd or even in java,how to check if number is even or odd,simple check the given number is even or odd numbers in java,check even or odd without using % and & operators in java,even odd program without if else statement,how to check even number in java,if statement
Рекомендации по теме
Комментарии
Автор

Here's are simply used Conditional Operator:

The Conditional Operator is used to select one of two expressions for
evaluation, which is based on the value of the first operands. It is used
to handling simple situations in a line.
Syntax:
expression1 ? expression2:expression3;
The above syntax means that if the value given in Expression1 is true,
then Expression2 will be evaluated; otherwise, expression3 will be
evaluated.

MOHIT___
Автор

📌Checking a number Even or Odd without if statement.

🔹#Method1
//Indexing into an array
int num = 7;
string result = new[]{"Even", "Odd"}[num%2];
print(result);

🔹#Method2
//Indexing into an array
int num = 7;
string[] result = {"Even", "Odd"};
print(result[num%2]);

🔹#Method3
//Ternary operation
int num = 7;
result = num%2==0?"Even":"Odd";
print(result);

🔹#Method4
//Bitwise operation
int num = 7;
result = num&1==0?"Even":"Odd";
print(result);

🔹#Method5
//Functional Paradigm for reuseability/readability
var chkEO = n => n%2==0?"Even":"Odd";
int num = 7;
print(chkEO(num);

🔹#Method6 (Pure functions)
//It's highly technical. You won't understand without learning it in the below links! :3
#Link1
#Link2

//Contents: Encoding datatypes section from above link 1

TRUE := λab.a
FALSE:= λab.b
NOT:= λf.f FALSE TRUE

ZERO := λfx.x
ONCE := λfx.f x
TWICE := λfx.f (f x)

isEven := λn.n NOT TRUE

//Created output function to see the result
toBool := λf.f true false

toBool(isEven(ONCE)); //false
toBool(isEven(TWICE)); //true

ayechanaungthwin-goat
Автор

I have used it several timestamp before I have seen this here in my class 9 and 10 ICSE exams very fun to use it atleast I can get rid of if else statements which takes 4 to 5 lines to just 1 line 😂

atharvagarg
Автор

"Even"*n%2+"Odd"*n%2
Or
{"Even", "Odd"}[n%2]

saleemhafiz
Автор

Tomorrow is my JAVA Exam Bro and I'm studying hard. I'm here to break and refresh mind but here are also study part 😂


Nice content 👍

MOHIT___
welcome to shbcf.ru