Determine triangle type WITHOUT logical operators JAVA

coinbird

I'm supposed to write two programs to determine the type of triangle, given side lengths. One program can use logical operators. One can not. Here's my solution to the first program:

if (S1 == S2 AND S2 == S3)
    System.out.println("equalateral");
else if (S1 == S2 OR S2 == S3 OR S1 == S3)
    System.out.println("isoceles");
else
    System.out.println("scalene");

I think that part is correct, but I'm totally drawing a blank as to how I would NOT use logical operators. I thought maybe something with boolean, but that just goes back to me using logical operators. The exact directions are,

"Write the code using nested if-else statements, where every if has a matching else block and all if conditions are simple conditions, with no logical operators in them."

Can someone point me in the right direction?

nhgrif

First off, there is no AND or OR in Java. Try && and ||.

But alternative to the logical operators, you can use the comparison operators.

if(S1 == S2) {
    if(S2 == S3) {
        //equilateral
    } else {
        //isosceles
    }
} else if(S2 == S3) {
    //isosceles
} else {
    //scalene
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Determine a menu choice without using logical operators, relational operators, or selection constructs

From Dev

What is the type of the logical operators?

From Dev

Java logical operators

From Dev

Why Logical operators, when there is Bitwise operators in java

From Dev

Java method that returns logical operators

From Dev

Logical comparison operators without control statements

From Dev

Rounding integer division without logical operators

From Dev

Check Triangle Type in Java

From Dev

why java revert logical operators while compile

From Dev

Combining Java 8 lambda predicates with logical operators

From Dev

How are expression with logical operators evaluated in Java?

From Dev

How to determine the logical type of a linux network device

From Dev

Logical AND (&&) and OR (||) operators

From Dev

Logical AND (&&) and OR (||) operators

From Dev

Logical operators

From Dev

Logical Operators and increment operators

From Dev

How to determine the class type of generic property in java without reflection?

From Dev

How to print 2 characters in C without using logical operators?

From Dev

Java determine type of class

From Dev

More elegant syntax for logical operators for equals() method in Java?

From Dev

Object.equals(Boolean, Boolean) vs Logical Operators (Java)

From Dev

While java provides non short-circuit version of logical operators (like logical |, &), when are these required?

From Dev

Logical operators with three lists

From Dev

Logical Operators in Tweepy Filter

From Dev

Precedence of the shell logical operators &&, ||

From Dev

Combining logical operators in Ruby

From Dev

Are logical operators in assertions acceptable?

From Dev

Vectorizing logical operators in Excel

From Dev

Logical operators on enums

Related Related

  1. 1

    Determine a menu choice without using logical operators, relational operators, or selection constructs

  2. 2

    What is the type of the logical operators?

  3. 3

    Java logical operators

  4. 4

    Why Logical operators, when there is Bitwise operators in java

  5. 5

    Java method that returns logical operators

  6. 6

    Logical comparison operators without control statements

  7. 7

    Rounding integer division without logical operators

  8. 8

    Check Triangle Type in Java

  9. 9

    why java revert logical operators while compile

  10. 10

    Combining Java 8 lambda predicates with logical operators

  11. 11

    How are expression with logical operators evaluated in Java?

  12. 12

    How to determine the logical type of a linux network device

  13. 13

    Logical AND (&&) and OR (||) operators

  14. 14

    Logical AND (&&) and OR (||) operators

  15. 15

    Logical operators

  16. 16

    Logical Operators and increment operators

  17. 17

    How to determine the class type of generic property in java without reflection?

  18. 18

    How to print 2 characters in C without using logical operators?

  19. 19

    Java determine type of class

  20. 20

    More elegant syntax for logical operators for equals() method in Java?

  21. 21

    Object.equals(Boolean, Boolean) vs Logical Operators (Java)

  22. 22

    While java provides non short-circuit version of logical operators (like logical |, &), when are these required?

  23. 23

    Logical operators with three lists

  24. 24

    Logical Operators in Tweepy Filter

  25. 25

    Precedence of the shell logical operators &&, ||

  26. 26

    Combining logical operators in Ruby

  27. 27

    Are logical operators in assertions acceptable?

  28. 28

    Vectorizing logical operators in Excel

  29. 29

    Logical operators on enums

HotTag

Archive