Basics Java

Basics Java

Operators In Java

  1. Arithmetic Operator example: -,+,/,*,%-----------/ gives quotient, % gives remainder
  2. Relation Operator----output is always boolean ie true or false <,>,<=,>=,==,!=
  3. logical Operator or-- ||, and -- &&, not -- !

Conditional Statements

  1. if-else syntax: if(condition_true){

         }else{
               //when condition is false   }
    
  2. if-elseif ladder

syntax: if(condition_true){ }else if(condition_in_if fails_only_then){ }else{ //when both if and elsif fail

}

  1. switch case

switch(number){ case 1: default: }

if no break written all from case matched to default will be executed

Loops

1.while 2.do-while 3.for

a. while(condition_true){//we dont know the number of iteration}
b. for(int i=0;condition;I++){we know the number of iteration}
c. do-while--- first run is mandatory

do{ }while(condition)//go back to do when true else leave the loop