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

Android Tutorial:-How to create View Pager With Cover-Flow-Teachmeandroidhub(An animation Under Viewpager).

View-Pager  with Cover-flow  :- This Android tutorial  is all about how to create a wonderful  layout using-view pager  with some special  effect  that called carousel effect also to do such  layout  you don’t need  to add  any  dependencies  to  the  gradle  so let’s start this  tutorial first of all just need to create new Project in android studio I hope you know about how to create new project in android studio   Step -1:- In  this step you have create main activity that may be created with your  new project  creation this layout contain view pager that will adapt image view that I am going to show in this tutorial Activity_main.xml <? xml version= "1.0" encoding= "utf-8" ?> < LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"     xmlns: tools = "http://schemas.android.com/tools"     android :id= "@+id/activity_main_layout"     android :layout_width= "match_pa

retrofit android-Post Data Using Retrofit in Android -Teachmeandroidhub

Teachmeandroidhub Retrofit android-Post Data Using Retrofit in Android: Let's start work with Retrofit in android retrofit is most latest library that work with Rest Api. it is fast and easiest way to posting and getting data from server . Basically retrofit works on okhttp and we use retrofit android for sending data to json on internet so  in this topic I'll explain how to post data using Retrofit Step by step that how to work  Retrofit in android . Step -1. Create a new Project name it as you want Step -2. Add Dependencies in app level gradle like below     compile 'com.squareup.retrofit2:retrofit:2.1.0'     compile 'com.google.code.gson:gson:2.6.2'     compile 'com.squareup.retrofit2:converter-gson:2.1.0' Step -3  Design your UI with XML Like  activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

Privacy Policy AR Player App

                                   Privacy Policy AR Player App Privacy Policy Decode Technologies built the AR Player app as a Free app. This SERVICE is provided by Decode Technologies at no cost and is intended for use as is. This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service. If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy. The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at AR Player unless otherwise defined in this Privacy Policy. Information Collection and Use For a better experience, while using our Service, I may require you to provide us with certain persona