















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
















class Fibonacci { public static void main(String[] arg) { int lo = 1; int hi = 1; System.out.println(lo); while (hi < 50) { System.out.println(hi); hi = lo + hi; lo = hi โ lo; } } } 8
๏ โฆ
๏ class ArithmeticDemo { ๏ public static void main (String[] args){ ๏ int result = 1 + 2; // result is now 3 System.out.println(result); ๏ result = result - 1; // result is now 2 System.out.println(result); ๏ result = result * 2; // result is now 4 System.out.println(result); ๏ result = result / 2; // result is now 2 System.out.println(result); ๏ result = result + 8; // result is now 10 ๏ result = result % 7; // result is now 3 ๏ System.out.println(result); } } ๏ You can also combine the arithmetic operators with the simple assignment operator to create compound assignments. For example, ๏ x+=1; and ๏ x=x+1; both increment the value of x by 1.
๏ The unary operators require only one operand; they perform various operations such as incrementing/decrementing a value by one, negating an expression, or inverting the value of a boolean. ๏ + Unary plus operator; indicates positive value (numbers are positive without this, however) ๏ - Unary minus operator; negates an expression ๏ ++ Increment operator; increments a value by 1 ๏ -- Decrement operator; decrements a value by 1 ๏! Logical complement operator; inverts the value of a boolean