Skip to content

Commit a1e408a

Browse files
committed
Decision Statements Added
1 parent 429a1f3 commit a1e408a

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

decision1.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import java.util.*;
2+
3+
class decision1{
4+
public static void main(String[] a){
5+
6+
// Working with Conditional Statements
7+
int i;
8+
9+
Scanner scn = new Scanner(System.in);
10+
System.out.print("Enter a number here : ");
11+
i = scn.nextInt();
12+
13+
// Using Flow Control Statements
14+
// 1. First Type of using Control Flow statements
15+
if(i%2 == 0){ // for first condition
16+
System.out.println("The given number is even number !");
17+
}
18+
else{ // for otherwise condition
19+
System.out.println("The given number is odd number !");
20+
}
21+
22+
// 2. Second Type of using control flow statements
23+
// checking Two conditions by nested if condition
24+
int age;
25+
26+
System.out.print("Enter your age here : ");
27+
age = scn.nextInt();
28+
if(age < 25){
29+
if(age <= 18){
30+
System.out.println("You are a teenager !");
31+
}
32+
else{
33+
System.out.println("You are a Youth Now !");
34+
}
35+
}
36+
else{
37+
System.out.println("You are not a Teenager !");
38+
}
39+
40+
// Using else if for multiple conditional statement
41+
int number;
42+
43+
// taking input
44+
System.out.print("Enter a number here : ");
45+
number = scn.nextInt();
46+
47+
// Applying the conditions here
48+
if(number > 0){
49+
System.out.println("The number you entered a positive number !");
50+
}
51+
else if(number < 0){
52+
System.out.println("You have entered a negative number !");
53+
}
54+
else{
55+
System.out.println("Wrong Choice !");
56+
}
57+
58+
// Note : We can also apply multiple else if condition on the place of using multiple if statement
59+
60+
// Using Switch statement and its cases
61+
switch(number){
62+
case 0:
63+
System.out.println("You are at the center of postive and negative number !");
64+
break;
65+
66+
case 5:
67+
System.out.println("You have entered an estimate limit number !");
68+
break;
69+
70+
default:
71+
System.out.println("This is a default statement !");
72+
}
73+
74+
}
75+
}

0 commit comments

Comments
 (0)