SlideShare una empresa de Scribd logo
1 de 10
&¨ )( © ¤¢('¨''¨%$                               ¥§#
                                            )¥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):




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

Más contenido relacionado

Similar a Mgd01 lab01to03

globes-it-donitza-pr
globes-it-donitza-prglobes-it-donitza-pr
globes-it-donitza-pr
Ido Manor
 
document redesign project
document redesign projectdocument redesign project
document redesign project
Resa Lehman
 
Ellzey 5611 module 3
Ellzey 5611 module 3Ellzey 5611 module 3
Ellzey 5611 module 3
cellzey
 
Semantic Web Vo Camp Seoul Summer Rdf Vocabularies
Semantic Web Vo Camp Seoul   Summer Rdf VocabulariesSemantic Web Vo Camp Seoul   Summer Rdf Vocabularies
Semantic Web Vo Camp Seoul Summer Rdf Vocabularies
sangwon Yang
 
15 champs de vecteurs sur r3
15 champs de vecteurs sur r315 champs de vecteurs sur r3
15 champs de vecteurs sur r3
Achraf Ourti
 
Limites et perspectives du cinéma d'horreur français
Limites et perspectives du cinéma d'horreur françaisLimites et perspectives du cinéma d'horreur français
Limites et perspectives du cinéma d'horreur français
AmauryPascaud
 

Similar a Mgd01 lab01to03 (20)

globes-it-donitza-pr
globes-it-donitza-prglobes-it-donitza-pr
globes-it-donitza-pr
 
Mgd10 lab03
Mgd10 lab03Mgd10 lab03
Mgd10 lab03
 
Mgd09 lab03
Mgd09 lab03Mgd09 lab03
Mgd09 lab03
 
Argentina (Cordoba) elections 2015
Argentina (Cordoba) elections 2015Argentina (Cordoba) elections 2015
Argentina (Cordoba) elections 2015
 
MSME Conclave - Facilitating Financing & Enhancing Competitiveness
MSME Conclave - Facilitating Financing & Enhancing CompetitivenessMSME Conclave - Facilitating Financing & Enhancing Competitiveness
MSME Conclave - Facilitating Financing & Enhancing Competitiveness
 
document redesign project
document redesign projectdocument redesign project
document redesign project
 
Quinones Final Design
Quinones Final DesignQuinones Final Design
Quinones Final Design
 
TG51
TG51TG51
TG51
 
Ellzey 5611 module 3
Ellzey 5611 module 3Ellzey 5611 module 3
Ellzey 5611 module 3
 
Sample Interview Question
Sample Interview QuestionSample Interview Question
Sample Interview Question
 
C++interviewquestions
C++interviewquestionsC++interviewquestions
C++interviewquestions
 
Semantic Web Vo Camp Seoul Summer Rdf Vocabularies
Semantic Web Vo Camp Seoul   Summer Rdf VocabulariesSemantic Web Vo Camp Seoul   Summer Rdf Vocabularies
Semantic Web Vo Camp Seoul Summer Rdf Vocabularies
 
15 champs de vecteurs sur r3
15 champs de vecteurs sur r315 champs de vecteurs sur r3
15 champs de vecteurs sur r3
 
Dispositivi per la telemedicina
Dispositivi per la telemedicinaDispositivi per la telemedicina
Dispositivi per la telemedicina
 
Limites et perspectives du cinéma d'horreur français
Limites et perspectives du cinéma d'horreur françaisLimites et perspectives du cinéma d'horreur français
Limites et perspectives du cinéma d'horreur français
 
Educação Ambiental através do Espaço Construído da Escola
Educação Ambiental através do Espaço Construído da EscolaEducação Ambiental através do Espaço Construído da Escola
Educação Ambiental através do Espaço Construído da Escola
 
earth2012
earth2012earth2012
earth2012
 
Novela La Rebelión de Ayn Rand
Novela La Rebelión de Ayn RandNovela La Rebelión de Ayn Rand
Novela La Rebelión de Ayn Rand
 
Dav Body
Dav BodyDav Body
Dav Body
 
Dopon!
Dopon!Dopon!
Dopon!
 

Más de Hock Leng PUAH

CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
Hock Leng PUAH
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe Project
Hock Leng PUAH
 

Más de Hock Leng PUAH (20)

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

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): ¥ § # ¡ ¨ )( © ¤¢('¨''¨%$