Lesson 8 - Activity 2 - Are there other operators you can use in Java?

Time: 10 minutes

Purpose: Explore other operators available in Java

Introduction: You’re covered operators such as =, <, >, == it’s time to search for others.

Task: Investigate other operator types.

Decide which type of operator class they fall into – are they assignment, arithmetic, string, relational or logical?

Have a go using them.

public static void playingAroundWithUnaryOperators () {

    double num = 17.8;
    boolean bool = false;

    System.out.println("We start with this number = " + num);
    System.out.println("We start with this boolean called flag = " + bool);

    System.out.println("+number = " + +num);
    System.out.println("-number = " + -num);
    System.out.println("++number = " + ++num);
    System.out.println("++number = " + num++);
    System.out.println("++number = " + ++num);
    System.out.println("++number = " + num++);
    System.out.println("--number = " + --num);
    System.out.println("--number = " + num--);
    System.out.println("--number = " + --num);
    System.out.println("--number = " + num--);
    System.out.println("!bool = " + !bool);
    System.out.println("!!!!bool = " + !!!!bool);
}

So which class do you think unary operators fall under?