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:
It is a type of DMS which is used to make a decision to execute a set of statements based on single condition.
- class DMSoperators
- {
- public static void main(String [] args)
- {
- int a= 25;
- if(a%2==0)
- {
- System.out.println("Number is even");
- }
- System.out.println("Remaining statement");
- }
- }
Output:
Remaining statement
2. if - else
- class DMSoperators
- {
- public static void main(String [] args)
- {
- int a= 24;
- if(a%2==0)
- {
- System.out.println("Number is even");
- }
- else
- {
- System.out.println("Number is odd");
- }
- System.out.println("Remaining statement");
- }
- }
Output:
Number is even
Remaining statement
3. Ladder (if-else-if)
- class DMSoperators
- {
- public static void main(String [] args)
- {
- int M= 62;
- if(M>=90 && M<=100)
- {
- System.out.println("Excellent");
- }
- else if(M>=75 && M<=89)
- {
- System.out.println("Very Good");
- }
- else if(M>=60 && M<=74)
- {
- System.out.println("1st class");
- }
- else if(M>=35 && M<=59)
- {
- System.out.println("2nd class");
- }
- else if(M<35)
- {
- System.out.println("Fail");
- }
- }
- }
Output:
1st class
4. Nested DMS
- One DMS inside another DMS is known as Nested DMS.
program
- class DMSoperators
- {
- public static void main(String [] args)
- {
- int ch= '*';
- if(ch>='A' && ch<='Z')
- {
- if(ch=='A' | | ch=='O' | | ch=='I' | | ch=='E' | | ch=='U')
- {
- System.out.println("Uppercase vowel");
- }
- else
- {
- System.out.println("Uppercase consonant");
- }
- if(ch>='a' && ch<='z')
- {
- if(ch=='a' | | ch=='e' | | ch=='i' | | ch=='o' | | ch=='u')
- {
- System.out.println("Lowercase vowel");
- }
- else
- {
- System.out.println("Lowercase consonant");
- }
- if(ch>='1' && ch<='9')
- {
- System.out.println("Number");
- }
- else
- {
- System.out.println("Special character");
- }
- }
- }
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:
- Switch can not take boolean, long, float or double as the input.
- Default statement is not compalsary we can have it without default also.
- Duplicate case is not allowed.
- Break statement is not mandatory we will used it when we want to execute a particular case.
- 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.
- class DMSoperators
- {
- public static void main(String [] args)
- {
- int press= 3;
- switch(press)
- {
- case 1 : System.out.println("Can talk in Hindi");
- break;
- case 2 : System.out.println("Can talk in English");
- break;
- case 3 : System.out.println("Can talk in Marathi");
- break;
- case 4 : System.out.println("Can talk in Punjabi");
- break;
- default : System.out.println("Buddy pass valid input");
- break;
- }
- }
- }
Output:
Can talk in Marathi
PROBLEMS
0 Comments