SlideShare a Scribd company logo
&¨ )( © ¤¢('¨''¨%$                               ¥§#
                                            )¥I  H¥† ’ ¥¤£@
        %“ £§)£¤§ ¥¤ © ) ’‘  £§)£¤§ §§ H¥ § ¥§¥E %C ¥…
                                          ‰(ˆ(‡ ©§¥¢¥† §… %7 ¥…
       „yrugƒr‚wwv gg€ syx wwv utsrq p` idc hgfedcba`
                                4UQYU2QX U2WVVQTU1TS QRQP
                             ©¥ §§I!'¥(©H$($§¨%$
                                                           %¥)¥¥B¥G
                     ©   '§ © ££' E %F6 ¢§ 876¦¡       o
              © £©¥ E '§ ©¥9D §§ %C6 ¢§ 876¦¡       o
          £§)£¤A §§  B A ©£@ 9¡ %76 ¢§ 876¦¡     o
                                       ¥§!§ £¨¨§  §§      •
                                                         53243210
           ¥§!§ £¨¨§  §§  ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡
¨ )( © ¤¢('¨''¨%$                           ¥§#(
   §
    £'¨S   §
              §£§†S     §
                            ©)¥I S            ¦¥¤£¢¡ )
                                 A§§©£@ %¥¨§ )¥I 
             ¥§!§ £¨¨§  §§  ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡
¨ )( © ¤¢('¨''¨%$                             ¥§#2
                   “‡@ )¥I  £§¡ !G ’ !G %!G '§ '¤£!  %D ¥…
                                                           }
                                                      }
   System.out.println(My First Java App);
       public static void main(String[] args) {
                                    public class Main {
                                 package firstjavaapp;
                                                   §§I(£§¡
                            %“'¥ £ ©¥' ) £H ¤¤ B ¥$ ''A %F ¥…
            ¥§!§ £¨¨§  §§  ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡
¨ )( © ¤¢('¨''¨%$                                         ¥§#3
                                                           ¡    ¥¤££! @¡£¥@ ¡ ¡ ¡ ¦¥ 8
                                X“¥£ ¥£(¥¤ © E(¨¥©9…X ¨E   §¤£¨£© ©£ X“¤£(! (¨¥©9…X “D
                                  £§)£¤§ ¥$ B  £  £§© ¥$ ©£ X“©£§¨ '£  )£§© )£¤¢!X “F
             X§§§I©£BX '¥¤¤§) ¥'¤ B § ¥'£©£ '¥)§¤ ©£ ©©§¤) ¥$ ¥£§¨£ ’‘ X§§§I©£B ¥§¦)§X
                                                                                        (£$©§¤) ¥¨§
'£ §   ©£ ¥© ! (¥)§©¥¨§ ¨E   §¤£¨£© ©£ § (¥' ) B  ¥£¤ ©£B ¥$ ¥¢ ©!¨ ' H9¥¦ X¥§¦)§X “C
                                                  ¡  ¥ ©©§¤) )£¤¢!             '§        §§I(¡  ¥
                  ¥¨§© ¥$ ¥¢ ©!¨ ¥¨§ £¥$ '§ ©©§¤) )£¤¢! ¥  £§ ) 9¤  §) ¥¤£B §§ 9¥¨ “7
                                                                                                    }
                                                                                              }
                                   System.out.println(My First Java App);
                                        public static void main(String[] args) {
                                                                           public class Main {
                                                                        package firstjavaapp;
                                                                                           §§I(£§¡
                                                                                ¤¤£¡£ £¡ ¢¢¢¡ ¢¤ £¢ ¡ ))
                                                ¥§!§ £¨¨§  §§  ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡
¥§!§ £¨¨§  §§  ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡


t„yrts¡„y£ ¢„g t¡wp  gugb i©c hgfedcba`

‰(ˆ(‡ ©§¥¢¥† §… %7 ¥…

©¥9D§§'A©¥¤¢§£§D %¥¨§ )¥I  ( £§)£¤§ §§ H¥ § ¥§¥E %C ¥…

%“¥!¤¢ £ ©¥' ) £H ¤¤ B ¥$ ''A %F ¥…

        §§I(£§¡

        package variablesanddatatypes;

        public class Main {

             public static void main(String[] args) {
                 // Variable: must begin with a letter or underscore and
                 // must consist entirely of letters, digits, and underscores.

                    /* Data types
                       - Primitives: byte, short, int, long, float, double,
                         char and boolean
                       - Objects: String
                    */
                    double capital = 200.0;
                    double interestRate = 0.01;

                    double subTotal = capital * interestRate;
                    System.out.println(SubTotal =  + Double.toString(subTotal));

                    // Using String
                    String input = 35;
                    double total = subTotal + Double.parseDouble(input);
                    System.out.println(Total =  + Double.toString(total));

                    // Using Math utility class
                    int length = 5;
                    double areaOfSquare = Math.pow(length, 2);
                    System.out.println(Area of Square =  + areaOfSquare );
             }

        }




¥§#B                   ¨ )( © ¤¢('¨''¨%$
¨ )( © ¤¢('¨''¨%$                                        ¥§#D
                                                                                     ““©£… D ¥ %¥©§)
¥! $£H §© 9¥$ ¥¨E  @ “©£…  ¥ %¥©§) ¥H ¤ $£H §© ©' $¥¨ ©©§¤)  B  £¥ ) £¨§† “I
                                                                                “©£… D( ¥¦£¤
          ©' $¥¨ H  £¥$ ¥§$ 9¥$ '§ ©)¥I¢  ¥§ D¨†( £ ¥9 §§' ¤¤§ ©§ ¨E ¨ B ¥¥BB£
                                                 “©¥¤¢! ¥©§(¥¤¢!  '§ “©£… (¥¤¢! 
                                                                          %£©!  £©¥ ) ¥9 §§ “D
                                                                                   £… ©£ ¥9 )¥I¢  i
                             §¥¤  ¢ '§ §$) ¥¥¤¢! ' ¥§ ¤B ¥ ¤ ¥£ ¥ $© ¥¥9¢ ¥§ ©¥9 ¥££¨£ i
                                                                                                %©¥9 §§ “F
                           C¥¨§†89¨ ¥¥¨§†9¡ ¥¥¤¢§£§D¥§£8 %'£¤§ ¤¤§ ¥§ £H ¤¤ B ¥$D (©¥ )©¥'!
'§ ¥©££' ¥©¥¥¤ B  9¤¥£¥ ©£© ) ©!¨ '§ ¥ )©¥'!   ¥¥¤ § $£H £¥¢ ©!¨ %©¥¤¢§£§ B  ¥¨§† “C
                             ©¥¨¨ ) ¦) ¤¢  B ¡ (© ¡ G  ©¥¨¨ ) ¥£¤ ¥¤£©  B  ¥©e %©¥¨¨ E “7
                                                                                      ¤¤£¡£ £¡ ¢¢¢¡ ¢¤ £¢ ¡ ))
                                                      ¥§!§ £¨¨§  §§  ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡
¥§!§ £¨¨§  §§  ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡


twyyf ¢„g t„yrur¢„y£ i2c hgfedcba`

‰(ˆ(‡ ©§¥¢¥† §… %7 ¥…

©   'A£$)§  %¥¨§ )¥I  ( £§)£¤§ §§ H¥ § ¥§¥E %C ¥…

%“¥!¤¢ £ ©¥' ) £H ¤¤ B ¥$ ''A %F ¥…
       package conditionsandloops;

       enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY };

       public class Main {

            public static void main(String[] args) {

                 // do while loop
                 System.out.println(--do while loop--);
                 boolean wantsToContinue = true; // True to loop again.
                 int loopcount = 0;
                 do {
                      loopcount++; // add 1 to loopcount
                      if (loopcount == 10)
                          wantsToContinue = false; // check to set variable

                     System.out.println(Loop: + loopcount);
                 } while (wantsToContinue == true);    // check at the end
                 System.out.println(After do while loop);

                 // while loop to calculate
                 System.out.println(--while loop--);
                 int years = 0; // initialize the variable years
                 double interest, principal, rate;
                 principal = 1000.0;
                 rate = 0.01;
                 while (years  5) { // condition for continuing loop
                     interest = principal * rate; //
                     principal += interest; // do three statements

                      System.out.println(Year  + (years+1) + :  + principal);
                      years++; // update the value of the variable, years
                 }

                 // for loop, doing same thing as the above while loop
                 System.out.println(--for loop--);
                 principal = 1000.0;
                 for (years = 0; years  5; years++) {
                     interest = principal * rate;
                     principal += interest;
                     System.out.println(Year  + (years+1) + :  + principal);
                 }

                 // for each and enum Day


¥§#E                   ¨ )( © ¤¢('¨''¨%$
¥§!§ £¨¨§  §§  ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡


               // enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY }
               System.out.println(for each loop);

               for (Day d : Day.values()) {
                   System.out.print(d); // print the day
                   System.out.print( is day number );
                   System.out.println(d.ordinal()); // print the position
               }

               // if else
               System.out.println(--if else--);
               int myAge = 15;
               if (myAge  18) { // Check condition for above 18 yrs old
                   System.out.println(Under the Road Traffic Act,you can drive.);
               }
               else {            // otherwise, below 18 yrs old
                   System.out.println(Under the Road Traffic Act,you cannot drive.);
               }

               // switch and enum Day
               System.out.println(--switch--);
               Day day = Day.WEDNESDAY;
               switch (day)
               {
                   case MONDAY: System.out.println(Mon);
                                break;
                   case TUESDAY: System.out.println(Tue);
                                break;
                   case WEDNESDAY: System.out.println(Wed);
                   case THURSDAY:    System.out.println(Thu);
                   case FRIDAY:
                                System.out.println(Fri);
                                break;
                   default:
                                System.out.println(Default);
                                break;
               }

           }

      }




¥§#F                ¨ )( © ¤¢('¨''¨%$
¨ )( © ¤¢('¨''¨%$                                          ¥§#G
                                                                                                            }
                                                                                                       }
                                               } while (exitLoop.equalsIgnoreCase(N));
                                               exitLoop = scanner.nextLine();
                                               System.out.print(Exit loop (Y/N):);
                                               do {
                                               String exitLoop;
                                               Scanner scanner = new Scanner(System.in);
                                                     public static void main(String[] args) {
                                                                                     public class Main {
                                                                                    ¤¥§)…(¤£!(§§I  ¨£ %£s
                                                           (¨§  ¥$ £‰¥   ©¥©  $) ¥©! ¥$ ¤£! $! $
          ¤   ¨§  ¥ ¢§ ¥$ 9B£' ¨ ¥  ¤ ¥¤£$H  ' '§ “!£ ¥©! '§¥   ©©§¤) ¥§)… ¥$ £©e ¦( ¡ P
                                                                              Your total roll is 7
                                                                              The second die comes up 4
                                                                              The first die comes up 3
                                                   %¥¤¨§‰¥  @ (¤¤  ¤§  ¥$ '§ ¥£' $)§¥   £H $© ¥¢¨!
 ¥$  ¥ '¤! $© ¨§  !  (¤¤  ¤§  ¥$ ¥   ¥$¥  ¥!¤§ £¥$ ''§ '§ ¥£' ' )¥© ¥$  B £§§ £  
                                              + 1   int rolledNumber1 = (int) (Math.random() * 6)
     7¥¢¨!†'¥¤¤  ¥¤¢§£§ ¥$   £©©§ '§ ‡   7 ¨ B ¥¢¨! § ¥§¥¥ ¤¤£H ¥¨¥§© £H ¤¤ B ¥$D %£s
('¥¤¤  ©£ £ ¥B§ ¥£' ¥$   ¥¢¨! ¥$ ©¥©¥¥ ¦)£ ! 9 ¥¢¨! ¥$D (¨ '§ § ‡ ¥I ¥D ¥F ¥C ¥7 ©¥¥£ ¥$ B 
  ¥  £©  $) 9¢ ¥£' ¥  £¤¤  ¥§¤!¨£© §) !  (¥)£' B  £§ § B  £¤¤  ¥§¤!¨£© §$ ¨§  § ¥£ ¦ ¡ P
                                                                                                           ¡trƒs¡ H
                                                                        ¤ ‰¥ ¥$   ¨!I       %¥!£ )
                                                                        ¤ ¥$ B  !  ¨!I           %¦§¥¢
                                                                                        %¥!£ ) '§ ¦§¥¢ “F
         “I!$ ¤¤§B ¦§¤¢ 9¤  ¨) ¨ B ¥¥BB£'  $! $ ¤¤§B ©H ¤¤§ $)£H© $)£H© '§ ¥©¤¥ B£ %£$)§  “C
                           “¨) ¨ B ¥¥BB£' ©£ ‰§9©  $)§¥  B $)§¥  B '§  B ¥¥¤£$H ¥¥¤£$H  ' %©   “7
                                                                                        ¤¤£¡£ £¡ ¢¢¢¡ ¢¤ £¢ ¡ ))
                                                       ¥§!§ £¨¨§  §§  ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡
¥§!§ £¨¨§  §§  ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡


        The first die comes up 3
        The second die comes up 4
        Your total roll is 7
        Exit loop (Y/N):N
        The first die comes up 3
        The second die comes up 5
        Your total roll is 8
        Exit loop (Y/N):




¥  §  # ¡          ¨ )( © ¤¢('¨''¨%$

More Related Content

PDF
ぺっとぼーどご説明資料_ペット事業者様向け
PDF
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
PDF
Management komplexer Live Communication Portfolios
PDF
IIT-JEE Mains 2016 Online Previous Question Paper Day 2
PDF
Mgd08 lab01
PPT
Information Design
PDF
Melissa Crain Design Deliverables & A Dose Of Inspiration
PDF
Design To Deployment
ぺっとぼーどご説明資料_ペット事業者様向け
CakePHPをさらにDRYにする、ドライケーキレシピ akiyan.com 秋田真宏
Management komplexer Live Communication Portfolios
IIT-JEE Mains 2016 Online Previous Question Paper Day 2
Mgd08 lab01
Information Design
Melissa Crain Design Deliverables & A Dose Of Inspiration
Design To Deployment

Similar to Mgd01 lab01to03 (20)

PDF
globes-it-donitza-pr
PDF
Mgd10 lab03
PDF
Mgd09 lab03
PDF
Argentina (Cordoba) elections 2015
PDF
MSME Conclave - Facilitating Financing & Enhancing Competitiveness
PDF
document redesign project
PDF
Quinones Final Design
PDF
PDF
Ellzey 5611 module 3
PDF
C++interviewquestions
PDF
Sample Interview Question
PDF
Semantic Web Vo Camp Seoul Summer Rdf Vocabularies
PDF
15 champs de vecteurs sur r3
PDF
Thesis Abstract & Intro
PDF
Dispositivi per la telemedicina
PDF
Limites et perspectives du cinéma d'horreur français
PDF
Educação Ambiental através do Espaço Construído da Escola
PDF
earth2012
PDF
PDF
Novela La Rebelión de Ayn Rand
globes-it-donitza-pr
Mgd10 lab03
Mgd09 lab03
Argentina (Cordoba) elections 2015
MSME Conclave - Facilitating Financing & Enhancing Competitiveness
document redesign project
Quinones Final Design
Ellzey 5611 module 3
C++interviewquestions
Sample Interview Question
Semantic Web Vo Camp Seoul Summer Rdf Vocabularies
15 champs de vecteurs sur r3
Thesis Abstract & Intro
Dispositivi per la telemedicina
Limites et perspectives du cinéma d'horreur français
Educação Ambiental através do Espaço Construído da Escola
earth2012
Novela La Rebelión de Ayn Rand
Ad

More from Hock Leng PUAH (20)

PDF
ASP.net Image Slideshow
PDF
Visual basic asp.net programming introduction
PDF
Using iMac Built-in Screen Sharing
PDF
Hosting SWF Flash file
PDF
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PDF
PHP built-in function mktime example
PDF
A simple php exercise on date( ) function
PDF
Integrate jQuery PHP MySQL project to JOOMLA web site
PPTX
Responsive design
PDF
Step by step guide to use mac lion to make hidden folders visible
PPTX
Beautiful web pages
PPT
CSS Basic and Common Errors
PPTX
Connectivity Test for EES Logic Probe Project
PPTX
Logic gate lab intro
PDF
Ohm's law, resistors in series or in parallel
PPTX
Connections Exercises Guide
PPTX
Design to circuit connection
PPTX
NMS Media Services Jobshet 1 to 5 Summary
DOCX
Virtualbox step by step guide
PPTX
Nms chapter 01
ASP.net Image Slideshow
Visual basic asp.net programming introduction
Using iMac Built-in Screen Sharing
Hosting SWF Flash file
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in function mktime example
A simple php exercise on date( ) function
Integrate jQuery PHP MySQL project to JOOMLA web site
Responsive design
Step by step guide to use mac lion to make hidden folders visible
Beautiful web pages
CSS Basic and Common Errors
Connectivity Test for EES Logic Probe Project
Logic gate lab intro
Ohm's law, resistors in series or in parallel
Connections Exercises Guide
Design to circuit connection
NMS Media Services Jobshet 1 to 5 Summary
Virtualbox step by step guide
Nms chapter 01
Ad

Mgd01 lab01to03

  • 1. &¨ )( © ¤¢('¨''¨%$ ¥§# )¥I  H¥† ’ ¥¤£@ %“ £§)£¤§ ¥¤ © ) ’‘  £§)£¤§ §§ H¥ § ¥§¥E %C ¥… ‰(ˆ(‡ ©§¥¢¥† §… %7 ¥… „yrugƒr‚wwv gg€ syx wwv utsrq p` idc hgfedcba` 4UQYU2QX U2WVVQTU1TS QRQP ©¥ §§I!'¥(©H$($§¨%$ %¥)¥¥B¥G ©   '§ © ££' E %F6 ¢§ 876¦¡ o © £©¥ E '§ ©¥9D §§ %C6 ¢§ 876¦¡ o  £§)£¤A §§  B A ©£@ 9¡ %76 ¢§ 876¦¡ o ¥§!§ £¨¨§  §§ • 53243210 ¥§!§ £¨¨§  §§ ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡
  • 2. ¨ )( © ¤¢('¨''¨%$ ¥§#( §  £'¨S §  §£§†S § ©)¥I S ¦¥¤£¢¡ ) A§§©£@ %¥¨§ )¥I  ¥§!§ £¨¨§  §§ ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡
  • 3. ¨ )( © ¤¢('¨''¨%$ ¥§#2 “‡@ )¥I  £§¡ !G ’ !G %!G '§ '¤£!  %D ¥… } } System.out.println(My First Java App); public static void main(String[] args) { public class Main { package firstjavaapp; §§I(£§¡ %“'¥ £ ©¥' ) £H ¤¤ B ¥$ ''A %F ¥… ¥§!§ £¨¨§  §§ ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡
  • 4. ¨ )( © ¤¢('¨''¨%$ ¥§#3  ¡   ¥¤££! @¡£¥@ ¡ ¡ ¡ ¦¥ 8 X“¥£ ¥£(¥¤ © E(¨¥©9…X ¨E   §¤£¨£© ©£ X“¤£(! (¨¥©9…X “D  £§)£¤§ ¥$ B  £  £§© ¥$ ©£ X“©£§¨ '£  )£§© )£¤¢!X “F X§§§I©£BX '¥¤¤§) ¥'¤ B § ¥'£©£ '¥)§¤ ©£ ©©§¤) ¥$ ¥£§¨£ ’‘ X§§§I©£B ¥§¦)§X (£$©§¤) ¥¨§ '£ §   ©£ ¥© ! (¥)§©¥¨§ ¨E   §¤£¨£© ©£ § (¥' ) B  ¥£¤ ©£B ¥$ ¥¢ ©!¨ ' H9¥¦ X¥§¦)§X “C ¡  ¥ ©©§¤) )£¤¢! '§ §§I(¡  ¥ ¥¨§© ¥$ ¥¢ ©!¨ ¥¨§ £¥$ '§ ©©§¤) )£¤¢! ¥  £§ ) 9¤  §) ¥¤£B §§ 9¥¨ “7 } } System.out.println(My First Java App); public static void main(String[] args) { public class Main { package firstjavaapp; §§I(£§¡ ¤¤£¡£ £¡ ¢¢¢¡ ¢¤ £¢ ¡ )) ¥§!§ £¨¨§  §§ ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡
  • 5. ¥§!§ £¨¨§  §§ ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡ t„yrts¡„y£ ¢„g t¡wp  gugb i©c hgfedcba` ‰(ˆ(‡ ©§¥¢¥† §… %7 ¥… ©¥9D§§'A©¥¤¢§£§D %¥¨§ )¥I  ( £§)£¤§ §§ H¥ § ¥§¥E %C ¥… %“¥!¤¢ £ ©¥' ) £H ¤¤ B ¥$ ''A %F ¥… §§I(£§¡ package variablesanddatatypes; public class Main { public static void main(String[] args) { // Variable: must begin with a letter or underscore and // must consist entirely of letters, digits, and underscores. /* Data types - Primitives: byte, short, int, long, float, double, char and boolean - Objects: String */ double capital = 200.0; double interestRate = 0.01; double subTotal = capital * interestRate; System.out.println(SubTotal = + Double.toString(subTotal)); // Using String String input = 35; double total = subTotal + Double.parseDouble(input); System.out.println(Total = + Double.toString(total)); // Using Math utility class int length = 5; double areaOfSquare = Math.pow(length, 2); System.out.println(Area of Square = + areaOfSquare ); } } ¥§#B ¨ )( © ¤¢('¨''¨%$
  • 6. ¨ )( © ¤¢('¨''¨%$ ¥§#D ““©£… D ¥ %¥©§) ¥! $£H §© 9¥$ ¥¨E  @ “©£…  ¥ %¥©§) ¥H ¤ $£H §© ©' $¥¨ ©©§¤)  B  £¥ ) £¨§† “I “©£… D( ¥¦£¤ ©' $¥¨ H  £¥$ ¥§$ 9¥$ '§ ©)¥I¢  ¥§ D¨†( £ ¥9 §§' ¤¤§ ©§ ¨E ¨ B ¥¥BB£ “©¥¤¢! ¥©§(¥¤¢!  '§ “©£… (¥¤¢!  %£©!  £©¥ ) ¥9 §§ “D £… ©£ ¥9 )¥I¢  i §¥¤  ¢ '§ §$) ¥¥¤¢! ' ¥§ ¤B ¥ ¤ ¥£ ¥ $© ¥¥9¢ ¥§ ©¥9 ¥££¨£ i %©¥9 §§ “F C¥¨§†89¨ ¥¥¨§†9¡ ¥¥¤¢§£§D¥§£8 %'£¤§ ¤¤§ ¥§ £H ¤¤ B ¥$D (©¥ )©¥'! '§ ¥©££' ¥©¥¥¤ B  9¤¥£¥ ©£© ) ©!¨ '§ ¥ )©¥'!   ¥¥¤ § $£H £¥¢ ©!¨ %©¥¤¢§£§ B  ¥¨§† “C ©¥¨¨ ) ¦) ¤¢  B ¡ (© ¡ G  ©¥¨¨ ) ¥£¤ ¥¤£©  B ¥©e %©¥¨¨ E “7 ¤¤£¡£ £¡ ¢¢¢¡ ¢¤ £¢ ¡ )) ¥§!§ £¨¨§  §§ ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡
  • 7. ¥§!§ £¨¨§  §§ ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡ twyyf ¢„g t„yrur¢„y£ i2c hgfedcba` ‰(ˆ(‡ ©§¥¢¥† §… %7 ¥… ©   'A£$)§  %¥¨§ )¥I  ( £§)£¤§ §§ H¥ § ¥§¥E %C ¥… %“¥!¤¢ £ ©¥' ) £H ¤¤ B ¥$ ''A %F ¥… package conditionsandloops; enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY }; public class Main { public static void main(String[] args) { // do while loop System.out.println(--do while loop--); boolean wantsToContinue = true; // True to loop again. int loopcount = 0; do { loopcount++; // add 1 to loopcount if (loopcount == 10) wantsToContinue = false; // check to set variable System.out.println(Loop: + loopcount); } while (wantsToContinue == true); // check at the end System.out.println(After do while loop); // while loop to calculate System.out.println(--while loop--); int years = 0; // initialize the variable years double interest, principal, rate; principal = 1000.0; rate = 0.01; while (years 5) { // condition for continuing loop interest = principal * rate; // principal += interest; // do three statements System.out.println(Year + (years+1) + : + principal); years++; // update the value of the variable, years } // for loop, doing same thing as the above while loop System.out.println(--for loop--); principal = 1000.0; for (years = 0; years 5; years++) { interest = principal * rate; principal += interest; System.out.println(Year + (years+1) + : + principal); } // for each and enum Day ¥§#E ¨ )( © ¤¢('¨''¨%$
  • 8. ¥§!§ £¨¨§  §§ ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡ // enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY } System.out.println(for each loop); for (Day d : Day.values()) { System.out.print(d); // print the day System.out.print( is day number ); System.out.println(d.ordinal()); // print the position } // if else System.out.println(--if else--); int myAge = 15; if (myAge 18) { // Check condition for above 18 yrs old System.out.println(Under the Road Traffic Act,you can drive.); } else { // otherwise, below 18 yrs old System.out.println(Under the Road Traffic Act,you cannot drive.); } // switch and enum Day System.out.println(--switch--); Day day = Day.WEDNESDAY; switch (day) { case MONDAY: System.out.println(Mon); break; case TUESDAY: System.out.println(Tue); break; case WEDNESDAY: System.out.println(Wed); case THURSDAY: System.out.println(Thu); case FRIDAY: System.out.println(Fri); break; default: System.out.println(Default); break; } } } ¥§#F ¨ )( © ¤¢('¨''¨%$
  • 9. ¨ )( © ¤¢('¨''¨%$ ¥§#G } } } while (exitLoop.equalsIgnoreCase(N)); exitLoop = scanner.nextLine(); System.out.print(Exit loop (Y/N):); do { String exitLoop; Scanner scanner = new Scanner(System.in); public static void main(String[] args) { public class Main { ¤¥§)…(¤£!(§§I  ¨£ %£s (¨§  ¥$ £‰¥   ©¥©  $) ¥©! ¥$ ¤£! $! $   ¤   ¨§  ¥ ¢§ ¥$ 9B£' ¨ ¥  ¤ ¥¤£$H  ' '§ “!£ ¥©! '§¥   ©©§¤) ¥§)… ¥$ £©e ¦( ¡ P Your total roll is 7 The second die comes up 4 The first die comes up 3 %¥¤¨§‰¥  @ (¤¤  ¤§  ¥$ '§ ¥£' $)§¥   £H $© ¥¢¨! ¥$  ¥ '¤! $© ¨§  !  (¤¤  ¤§  ¥$ ¥   ¥$¥  ¥!¤§ £¥$ ''§ '§ ¥£' ' )¥© ¥$  B £§§ £   + 1 int rolledNumber1 = (int) (Math.random() * 6) 7¥¢¨!†'¥¤¤  ¥¤¢§£§ ¥$   £©©§ '§ ‡   7 ¨ B ¥¢¨! § ¥§¥¥ ¤¤£H ¥¨¥§© £H ¤¤ B ¥$D %£s ('¥¤¤  ©£ £ ¥B§ ¥£' ¥$   ¥¢¨! ¥$ ©¥©¥¥ ¦)£ ! 9 ¥¢¨! ¥$D (¨ '§ § ‡ ¥I ¥D ¥F ¥C ¥7 ©¥¥£ ¥$ B  ¥  £©  $) 9¢ ¥£' ¥  £¤¤  ¥§¤!¨£© §) !  (¥)£' B  £§ § B  £¤¤  ¥§¤!¨£© §$ ¨§  § ¥£ ¦ ¡ P ¡trƒs¡ H   ¤ ‰¥ ¥$   ¨!I %¥!£ )   ¤ ¥$ B  !  ¨!I %¦§¥¢ %¥!£ ) '§ ¦§¥¢ “F “I!$ ¤¤§B ¦§¤¢ 9¤  ¨) ¨ B ¥¥BB£' $! $ ¤¤§B ©H ¤¤§ $)£H© $)£H© '§ ¥©¤¥ B£ %£$)§  “C “¨) ¨ B ¥¥BB£' ©£ ‰§9© $)§¥  B $)§¥  B '§  B ¥¥¤£$H ¥¥¤£$H  ' %©   “7 ¤¤£¡£ £¡ ¢¢¢¡ ¢¤ £¢ ¡ )) ¥§!§ £¨¨§  §§ ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡
  • 10. ¥§!§ £¨¨§  §§ ¥¨ ¤¥¥ ©¥¨§¦ ¥¤£¢ ¡ The first die comes up 3 The second die comes up 4 Your total roll is 7 Exit loop (Y/N):N The first die comes up 3 The second die comes up 5 Your total roll is 8 Exit loop (Y/N): ¥ § # ¡ ¨ )( © ¤¢('¨''¨%$