Basicmath.java
// Demonstrate the basic arithmetic operators.public class BasicMath {public static void main (String [] args) {// arithmetic using integers System.out.println ( "Integer Arithmetic"); int a = 1 1; int b = A * 3; int C = B / 4; INT D = C - a; int E = -d; system.out.println ("a =" a); system.out.println ("b =" b ); System.out.println ("c =" c); system.out.println ("d =" d); system.out.println ("e =" e); // arithmetic using Doubles System .out.println ("/ nfloating point arithmetic"); double DA = 1 1; double db = da * 3; double DC = DB / 4; double DD = DC - a; double de = -dd; system.out .println ("DA =" DA); System.out.Println ("DB =" DB); System.out.Println ("DC =" DC); System.out.Println ("DD =" DD); system.out.println ("de =" de);}}
Modulus.java
// DemonStrate the% Operatorpublic class modulus {public static void main (string [] args) {int x = 42; double y = 42.25; system.out.println ("x mod 10 =" x% 10); system. Out.println ("y mod 10 =" y% 10);}}
Opequals.java
// DemonStrate Several Assignment Operators.public Class Opequals {public static void main (string [] args) {int a = 1; int b = 2; int C = 3; A = 5; b * = 4; C = A * b; c% = 6; system.out.println ("a =" a); system.out.println ("b =" b); system.out.println ("c =" c) }} Incognc.java
// DemonStrate public class inccDec {public static void main (string [] args) {INT A = 1; int b = 2; int C; int D; c = b; d = a ; C ; system. Out.println ("a =" a); system.out.println ("b =" b); system.out.println ("c =" c); system.out.println ("d =" D);}}
BitLogic.java
// DemonStrate the bitwise logical operatrs.public class bitlogic {public static void main (string "args) {string binary [] = {" 0000 "," 0001 "," 0010 "," 0011 "," 0100 "," 0101 "," 0110 "," 0111 "," 1000 "," 1001 "," 1010 "," 1011 "," 1100 "," 1101 "," 1110 "," 1111 "}; INT A = 3; / / 0 2 1 or 0011 in binary int b = 6; // 4 2 0 or 0110 in binary int c = a | b; int D = a & b; int E = a ^ b; int f = (~ a & b) | (A & ~ B); INT G = ~ a & 0x0f; system.out.println ("a =" binary [a]); system.out.println ("b =" Binary [b]); system.out.println ("a | b =" binary [c]); system.out.println ("a & b =" binary [d]); system.out.println ("a ^ b = " binary [e]); system.out.println (" (~ a & b) | (A & ~ B) = " binary [f]); system.out.println (" ~ a = " binary [g]);}} byteshift.java
// Left shifting a byte value.public class botteshift {public static void main (string [] args) {byte a = 64, b; int i; i = a << 2; b = (byte) (a << 2 ); System.out.println ("Original Value of A: a); System.out.Println (" i and b: " i " b);}}
MultByTwo.java
// LEFT SHIFTING AS A Quick Way to Multiply By 2.public Class MultBytwo {Public Static Void Main (String [] args) {INT i; int Num = 0xffffffe; for (i = 0; i <4; i ) {Num = Num << 1; System.out.Println (Num);}}} hexbyte.java
// masking Sign Extension.public class hEXBYTE {public static void main (string [] args) {char hex [] = {'0', '1', '2', '3', '4', '5' , '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; BYTE B = (Byte) 0xF1; System.out.println ("B = 0x" HEX [(B >> 4) & 0x0f] HEX [B & 0x0F]);}}
Byteushift.java
// unsigned shifting a byte value.public class byteushift {public static void main (string [] args) {char hex [] = {'0', '1', '2', '3', '4', ' 5 ',' 6 ',' 7 ',' 8 ',' 9 ',' A ',' B ',' C ',' D ',' E ',' F '}; BYTE B = (Byte) 0xf1; byte c = (byte) (B >> 4); BYTE D = (B >>> 4); Byte E = (BYTE) ((B & 0xFF) >> 4); system.out. Println ("b = 0x" hex [(b >> 4) & 0x0f] hex [b & 0x0f]); system.out.println ("b >> 4 = 0x" hex [(c >> 4 ) & 0x0f] hex [c & 0x0f]); system.out.println ("b >>> 4 = 0x" hex [(D >> 4) & 0x0f] HEX [D & 0x0F]); system .out.println ("(B & 0xFF) >> 4 = 0X" HEX [(E >> 4) & 0x0f] HEX [E & 0x0F]);}} OpBitequals.java
Package Chapter4; Public Class OpBitequals {Public Static Void Main (String [] args) {INT A = 1; INT B = 2; INT C = 3; A | = 4; B >> = 1; c << = 1; A ^ = C; System.out.Println ("a =" a); system.out.println ("b =" b); system.out.println ("c =" c);}}
BoolLogic.java
// Demonstrate the boolean logical Operators.Package Chapter4; public class bocess {public static void main (String [] args) {boolean a = true; boolean b = false; boolean c = a | b; boolean d = a & b; Boolean E = a ^ b; Boolean F = (! A & B); (A &! B); Boolean G =! A; System.out.Println ("a =" a); system.out.println "B =" b); system.out.println ("a | b =" c); system.out.println ("a & b =" d); system.out.println ("a ^ b =" E); System.out.println ("! A & B | A &! B =" f); system.out.println ("! a =" g);}} Ternary.java
// DemonStrate? .Public class ternary {public static void main (string [] args) {INT i, k; i = 10; k = i <0? -I: i; // Get Absolute value of i system.out .print ("Absolute Value of"); System.out.Println (i "IS" K); i = -10; k = i <0? -i: i; system.out.print ("Absolute value Of "); system.out.println (i " is " k);}}