Unit 2
Home-->Comp Sci
- Shortcut operators
- x+=2; x=x+2;
- y-=5; y=y-5;
- z*=value; z=z*vlaue;
- a/=10; a=a/10;
- num%=2; num=num%2;
- x++; x=x=1;
- x--; x=x-1;
- Random numbers
Random randy=new Random();
int x=randy.next(z);
- if z is left blank, will give a number within the systems limits
- if z is a number it is 0 to z-1 inclusive or (high-low+1)+low
- doubl nextDouble(); returns between 0.0(inclusive) to 1.0(exclusive)
- Control sutructures
if(boolean condition){executable statement(s)}
- if/else gives the option for an alternate set of instructions
- for loop is a reparition structure("fixed")
for(initialize counter; test condition; update counter){executable statement(s)}
- while loop will run maby times or not at all, due to a pre loop condition check, once not true it is terminated
while(boolean conditon)
- must change the control variable with in the loop
- do/while loop the condition is checked at the end, so it will always run at least once
do{ executable statements; }while(boolean condition);
- switch statement has an unlimited number of options
switch(variable){
case value1: executable statement(s);
break;
- nesting is placing a loop inside of another loop
- Relational operators
- > greater than
- < less than
- >= greater or equal to
- <= less or equal to
- == equal to
- != not equal to
- Compound boolean statements
- && and
- || or
- new order of operatoins
- grouping (),[]
- method selector .
- uniary minus -
- not !
- mult/divide/mod *,/,%
- add/sub +,-
- relational <,<=,>,>=,==,!=
- and &&
- or ||
- assignment =