← Java from Scratch Lesson 9 of 88 · 10 XP

Operators

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

  • arithmetic: + - * / %; with integers / drops the fractional part, and % is the remainder (with the sign of the dividend: -7 % 3 == -1);
  • assignment: = += -= *= /= %=; x++, ++x (increase first, then take the value);
  • comparison: == != < > <= >= — for primitives; strings are compared with .equals() (why — in the "Strings" lesson);
  • logic: &&, || (short-circuit), !;
  • bitwise: & | ^ ~ << >> >>> (>>> is an unsigned shift, which C doesn't have).
int x = 5;
int y = x++ + ++x;   // 5 + 7 = 12, x = 7 — don't write code like this, but do understand it

Task. Read a number of seconds and print h:mm:ss (minutes and seconds with two digits: String.format("%d:%02d:%02d", h, m, s)).

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.