Classes/Objects  «Prev 


Java Output Operator - Exercise

Objective:Identify the output of Java operators.

Instructions

This exercise is designed to let you check your understanding of Java operators. Analyze the program and identify each line of output displayed by the program. When you think you have identified all of them, click the Submit to see how you did.

public class ModuleReview {

  public static void main(String[] args) {
    int i = 123;
    String s = "456";
    System.out.println(i + s);
    System.out.println((int)i + s);
    s += i = i += 1 + 2 & 3 | 4 ^ 5;
    System.out.println(i);
    System.out.println(s);
    boolean b = i % 2 == 1;
    System.out.println(b);
    s = "" + (!b ^ b ? b & b : b | b); 
    System.out.println(b);
    System.out.println(s);
    b = b || b == b != b;
    System.out.println(b);
    s = "tr";
    String t = "" + b;
    s += "ue";
    System.out.println(s == t);
    System.out.println(s.equals(t));
  }
  
}

Exercise Scoring

The exercise is auto-scored, which means all you need to do to receive full credit for the exercise is click the Submit button.