Skip to main content

if-Statement in Java (Control Flow in Java)

Teachmeandroidhub #java #if-elese Statement

If-else Satament in Java

                                             If-Statement mainly used to test the condition in this case it returns true or false .Let's Assume a situation where you have been asked or said to execute a statement there may be a condition should be true or false. Let suppose you have done something wrong then your father will be ask  that have you done this or not you may return true or false .If retun true then you may be get slapped else some other good thing can be happen also with you.So apart from above there are some different type if-else statement are as following

  1. if Statement
  1. if-else Statement
  1. if-else-if Ladder
  1. nested if statement

 If Statement  in Java

1. If  Statement: -  Java  if condition check condition if  condition returns true then execute code under if block or if  condition returns false then exit.

Syntax

if(condition){ 

 //code to be executed 

}
in the above said syntax you can easily see how the condition written in if and statement in if block will execute after check if condition.


FlowChart of If Statement

Let's See an example on on if Statement&nbsp

public class IfExampleinJava {
   
    public static void main(String[] args) {  
    //defining an 'value' variable  
    int value=90;  
    //checking the value  
    if(value<100){  
        System.out.print("Oh no Century missed");  
    }  
}
    
}

output: Oh no Century missed

2. if-else Statement: - In above there was only if condition mean there was no statement in the case if condition returns false but in the if -else statement we hase an alternate if codition return we can execute some in the case else condition return false still we can execute some block of code let see the syntax


Flow Chart of  if-else Statement


Syntax

if(condition)
  { 
   //code if condition is true 
 }else
     { 
 //code if condition is false 
 }

lets See an Example on if-Else Statement


public class IfExampleinJava {
   
    public static void main(String[] args) {  
    //defining an 'value' variable  
    int value=90;  
    //checking the value  
    if(value>=100){  
        System.out.print("Century");  
    }else{
        System.out.print("it's Half Century ");  
    } 
}
    
}

Output:  it's Half Century

Comments

iniyan said…
I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.Surya Informatics

Popular posts from this blog

Types of Java Application | Java in Hindi by Rajeev lecture 1.1

Teachmeandroidhub

Retrofit Android-Fetching Data With Retrofit-teachmeandroidhub

Teachmeandroidhub             Retrofit Android:- This Tutorial is Develop to describe how to get or fetch data from server with Retrofit in Retrofit is latest Restful Api that  make data accessibility more easy and fast Earlier i i have discussed about post data using retrofit let's see how can be fetching data with Retrofit achieved in Retrofit android topic so let's start step by step and it;s 100% working Step-1 : Create  a Project  Define MainActivity as you want like this. This is may be your main activity in my Activity name is as following first You just Create at first You Create Layouts For this : activity_getusing.xml <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layo...

Set Environment variable for java jdk in hindi in windows10,8 1,8,,7 | J...

Gang