Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lessons;
- public class ArithmeticOperators
- {
- /*
- *
- * shortust to systm.out.print is 'syso'+Ctrl+space
- *
- */
- public static void main(String[] args)
- {
- // unary opertor needs one operand to affect change,
- //binary requries 2
- // turniariy requires 3
- System.out.println("Ex1, Unary Operand");
- int num = 5;
- num = -num;
- //this is unary operator bec it uses only one #
- System.out.println(" the unary operator requires"
- + " only one operand\n value: "+num);
- System.out.println("\nEx2, Addition Operator");
- int amount,total,priceA = 10, tax = 3, numA = 0;
- amount = 4+8;
- total = priceA + tax;
- numA = numA + 1;
- System.out.println(" the result of amount is: "+ amount
- +"\n the result of toal is: "
- + total+"\n the result of numA is: "+numA);
- System.out.println("\nEx3, Subtraction Operator");
- int temp, sale, priceB = 5, numB = 0, discount = 3;
- temp = 112 - 14;
- sale = priceB - discount;
- numB = numB - 1;
- System.out.println(" The temperature is: "+temp
- +"\n the result of sale is: "+sale
- +"\n the result of numB is: "+numB);
- System.out.println("\nEx4, Multipication Operator");
- int pop = 2;
- double markUp, percent = 0.02, sales = 3, commission;
- markUp = 12 * .25;
- commission = sales * percent;
- pop = pop * 2;
- System.out.println(" the markup is: "+markUp+
- "\n the commission is: "+commission+
- "\n the population is: "+pop);
- System.out.println("\nEx5, Division Operators");
- double points, teams, players=11, maxE=3,half,num3=23;
- points = 100/20;
- teams = players/maxE;
- half = num3/2;
- System.out.println(" points: "+points+
- "\n teams: "+teams+"\n half: "+half);
- System.out.println("\nEx6, Modulus Operator");
- //modulus gives remainder of division
- //ex. 11%2 is 1 bec 2 goes into 11 5 times with 1 left over
- int leftOver;
- leftOver = 17 % 3;
- System.out.println(" result of leftover is: "+leftOver);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement