• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 689
  • Last Modified:

Java If - then - else logic in one function

Is there a java function that provides "if-then-else" logic?

Example:  In Excel, you can use a function -  if (1=2,"False","True")

0
jbaird123
Asked:
jbaird123
  • 2
2 Solutions
 
leakim971PluritechnicianCommented:
Hello jbaird123,

Of course !

Check this :


boolean result = !(1==2);

Open in new window

0
 
mahomeCommented:
I'm not sure what you're looking for, but there are two ways I can consider. I think you mean the second one.

String result = null;
if (1 == 2) {
    result = "False";
} else {
    result = "True";
}

// or

String result = (1==2 ? "False" : "True");

Open in new window

0
 
leakim971PluritechnicianCommented:
or :


boolean result = (1==2)?false:true;

Open in new window

0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now