alternative
  • Home (current)
  • About
  • Tutorial
    Technologies
    C#
    Deep Learning
    Statistics for AIML
    Natural Language Processing
    Machine Learning
    SQL -Structured Query Language
    Python
    Ethical Hacking
    Placement Preparation
    Quantitative Aptitude
    View All Tutorial
  • Quiz
    C#
    SQL -Structured Query Language
    Quantitative Aptitude
    Java
    View All Quiz Course
  • Q & A
    C#
    Quantitative Aptitude
    Java
    View All Q & A course
  • Programs
  • Articles
    Identity And Access Management
    Artificial Intelligence & Machine Learning Project
    How to publish your local website on github pages with a custom domain name?
    How to download and install Xampp on Window Operating System ?
    How To Download And Install MySql Workbench
    How to install Pycharm ?
    How to install Python ?
    How to download and install Visual Studio IDE taking an example of C# (C Sharp)
    View All Post
  • Tools
    Program Compiler
    Sql Compiler
    Replace Multiple Text
    Meta Data From Multiple Url
  • Contact
  • User
    Login
    Register

Java - Decision Control and looping statement - If-else Tutorial

Java if-else statement is used to check the condition whether it is true or false. If the first condition is false then it will check the next condition, if the next condition also false, then it will finally run the else condition.

  • If statement

It executes if block only when if condition is true.

public class Ifcondition{

public static void main(String args[]){
int x=5;
if(x<6){
System.out.println("x is smaller than 6");
}
if(x<3){
System.out.println("x is smaller than 3");
}
}}

Run Program

Output -

x is smaller than 6
  • If-else statement

It checks first for if condition, if the condition is true, it will execute if block, else it will execute else block.

public class Ifelsecondition{
public static void main(String args[]){
int x=5;
if(x>6){
System.out.println("x is greater than 6");
}
else{
System.out.println("x is smaller than 6");
}
}}

Run Program

Output -

x is smaller than 6
  • If-else-if ladder

It checks first for if condition, if the condition is true, it will execute if block, otherwise it will go to next condition i.e else if.

If the condition went false, it will again move toward next else if condition, still the condition becomes true.

At last, if no condition is satisfied, finally it will execute else block.

public class Ifelsecondition{

public static void main(String args[]){
int x=6;
if(x>6){
System.out.println("x is greater than 6");
}
else if(x==6){
System.out.println("x is equal to 6");
}
else{
System.out.println("x is less than 6");
}

}}

Run Program

 

 Output -

x is equal to 6

 

 

Java

Java

  • Introduction
  • Installation and running a first java program
    • JDK Installation
    • Environment Variable Path Setup
    • Running a first java program
  • 1st Java Program Explanation
    • Program Syntax
  • JDK,JRE,JVM
    • JRE
    • JDK
    • JVM
  • Thing to know before proceed
    • Variable
    • Datatype
    • Operator
    • Keyword
    • Access Modifier
  • Decision Control and looping statement
    • If-else
    • Switch
    • For
    • While
    • do-while
    • break
    • continue
  • Object-Oriented Programming (OOPS) Concept
    • About OOPs
    • Object & Class
    • Inheritance
    • Polymorphism (Runtime & Compile Time)
    • Abstraction (Using abstract and interface)
    • Encapsulation

About Fresherbell

Best learning portal that provides you great learning experience of various technologies with modern compilation tools and technique

Important Links

Don't hesitate to give us a call or send us a contact form message

Terms & Conditions
Privacy Policy
Contact Us

Social Media

© Untitled. All rights reserved. Demo Images: Unsplash. Design: HTML5 UP.

Toggle