DMS - DECISION MAKING STATEMENT 




DMS - Decision Making Statement: 
  • It is a type of statement which is used to make a decision to execute a set of statement based on.
  • There are five types of DMS we have:
 1. if   
    It is a type of DMS which is used to make a decision to execute a set of statements based on single        condition.


  1. class DMSoperators
  2. {  
  3. public static void main(String [] args)
  4. {
  5. int a= 25
  6. if(a%2==0)
  7. {
  8. System.out.println("Number is even");
  9. }
  10. System.out.println("Remaining statement");
  11. }

Output:

Remaining statement                            
                                                              
                                                              

2. if - else



  1. class DMSoperators
  2. {  
  3. public static void main(String [] args)
  4. {
  5. int a= 24
  6. if(a%2==0)
  7. {
  8. System.out.println("Number is even");
  9. }
  10. else
  11. {
  12. System.out.println("Number is odd");
  13. }
  14. System.out.println("Remaining statement");
  15. }

Output:

Number is even                                     
Remaining statement                            
                                                              
                                                              

3. Ladder (if-else-if)


  1. class DMSoperators
  2. {  
  3. public static void main(String [] args)
  4. {
  5. int M= 62
  6. if(M>=90 && M<=100)
  7. {
  8. System.out.println("Excellent");
  9. }
  10. else if(M>=75 && M<=89)
  11. {
  12. System.out.println("Very Good");
  13. }
  14. else if(M>=60 && M<=74)
  15. {
  16. System.out.println("1st class");
  17. }
  18. else if(M>=35 && M<=59)
  19.  {
  20. System.out.println("2nd class");
  21.   }
  22. else if(M<35)
  23.   {
  24. System.out.println("Fail");
  25.    }
  26. }
  27. } 

Output:

1st class                                                 
                                                              
                                                              

4. Nested DMS
  • One DMS inside another DMS is known as Nested DMS.

program

  1. class DMSoperators
  2. {  
  3. public static void main(String [] args)
  4. {
  5. int ch= '*'
  6. if(ch>='A' && ch<='Z')
  7. {
  8. if(ch=='A' | | ch=='O' | | ch=='I' | | ch=='E' | | ch=='U')
  9. {
  10. System.out.println("Uppercase vowel");
  11. }
  12. else
  13. {
  14. System.out.println("Uppercase consonant");
  15. }
  16. if(ch>='a' && ch<='z')
  17. {
  18. if(ch=='a' | | ch=='e' | | ch=='i' | | ch=='o' | | ch=='u')
  19. {
  20. System.out.println("Lowercase vowel");
  21. }
  22. else
  23. {
  24. System.out.println("Lowercase consonant");
  25. }
  26. if(ch>='1' && ch<='9')
  27. {
  28. System.out.println("Number");
  29. }
  30. else
  31. {
  32. System.out.println("Special character");
  33. }
  34. }
  35. } 

Output:

Special character                                   
                                                              
                                                              


5. Switch
  • It is a type of DMS which is used to take a decision to execute a set of statements based on defferent values.

Note:
  1. Switch can not take boolean, long, float or double as the input.
  2. Default statement is not compalsary we can have it without default also.
  3. Duplicate case is not allowed.
  4. Break statement is not mandatory we will used it when we want to execute a particular case.
  5. Default statement can be used anywhere in the switch but it will be executed only after comparing all cases.
    Break:
  • It is a control transfer statement which is used to transfer the control outside the block.
  • Break a statement can be used to in switch and loop.        
  1. class DMSoperators
  2. {  
  3. public static void main(String [] args)
  4. {
  5. int press= 3
  6. switch(press)
  7. {
  8. case 1  : System.out.println("Can talk in Hindi");
  9.              break;
  10. case 2  : System.out.println("Can talk in English");
  11.              break;
  12. case 3  : System.out.println("Can talk in Marathi");
  13.              break;
  14. case 4  : System.out.println("Can talk in Punjabi");
  15.              break;
  16. default : System.out.println("Buddy pass valid input");
  17.              break;
  18. }
  19. }

Output:

Can talk in Marathi                                      
                                                               
                                                               




PROBLEMS