java if statement source code-Simple Java Programs
In this video I have shown the four common different if statements with example source code.
The four if statements are,
1. if statement
2. if-else statement
3. if-else-if ladder
4 .nested if statement
- Project Structure
-
If_Statement.java
package com.chillyfacts.com; public class If_Statement { public static void main(String[] args) { int i=15; System.out.println(i>10); if(i>10){ System.out.println("i is greater than 10"); } } }
Output
true i is greater than 10
- If_Else_Statement.java
package com.chillyfacts.com; public class If_Else_Statement { public static void main(String[] args) { int i=15; System.out.println(i>10); if(i>10){ System.out.println("i is greater than 10"); }else{ System.out.println("i is less than 10"); } } }
Output
true i is greater than 10
- If_Else_If_Statement.java
package com.chillyfacts.com; public class If_Else_If_Statement { public static void main(String[] args) { int i=60; if(i<5){ System.out.println("i is less than 5"); }else if(i<10){ System.out.println("i is less than 10"); }else{ System.out.println("i is greater than 10"); } } }
output
i is greater than 10
- Nested_If_Statement
package com.chillyfacts.com; public class Nested_If_Statement { public static void main(String[] args) { int i=16; //System.out.println(i>10); if(i<5){ System.out.println("i is less than 5"); }else if(i<10){ System.out.println("i is less than 10"); }else if(i<15){ System.out.println("i is less than 15"); }else if(i<20){ System.out.println("i is less than 20"); }else if(i<25){ System.out.println("i is less than 25"); }else{ System.out.println("i is greater than 25"); } System.out.println("Done"); } }
-
Download complete source code here
If_Else.rar
Output
i is less than 20 Done
0 Comments
Comments
Leave a Comment