Java instance exercises, java instances
1. Do not use the intermediate variable to swap two numbers
Public class Exchange {public static void main (String [] args) {role = new role (System. in); System. out. println ("enter an integer:"); Long num1 = numeric. nextLong (); System. out. println ("enter an integer:"); Long num2 = numeric. nextLong (); System. out. println ("pre-exchange num1:" + num1 + "pre-exchange num2:" + num2); num1 = num1 ^ num2; num2 = num2 ^ num1; num1 = num1 ^ num2; system. out. println ("num1:" + num1 + "num2:" + num2);} Exchange
2. Use the Three-object operator to determine parity
Public class ParityCheck {public static void main (String [] args) {custom partition = new partition (System. in); System. out. println ("enter an integer:"); Long num = bytes. nextLong (); String s = (num % 2 = 0 )? "This number is: even number": "This number is: Odd Number"; System. out. println (s) ;}} ParityCheck