Page 19 - PowerPoint Presentation
P. 19

If Statement











            If Statement example




                                         1.        public static void main(String[] args){

                                         2.          int length = sc.nextInt();


                                         3.          if(length<0) length = 0;


                                         4.          int price = length * 100;

                                         5.        }






                                       The length is converted to 0 only if length < 0
   14   15   16   17   18   19   20   21   22   23   24