Tuesday, 18 March 2025

Contact Info

  • ADDRESS: 851, LG, Sector 3F, Sector 3, Vaishali, Ghaziabad, Uttar Pradesh 201010

  • PHONE: +91 7986794481

  • E-MAIL: contact@technicalspeaks.com

  • Home  
  • Conditional Statements in Java| Switch Statement Java | Java if-else
- core java

Conditional Statements in Java| Switch Statement Java | Java if-else

In Java programming language, it is equipped with a specific statement through which we can check a condition and execute the code, depending on whether the condition is true or false. Such statements are called conditional statements and are a form of a composite statement also.  In Java, there are two types of conditional statements: […]

In Java programming language, it is equipped with a specific statement through which we can check a condition and execute the code, depending on whether the condition is true or false. Such statements are called conditional statements and are a form of a composite statement also. 

In Java, there are two types of conditional statements:

1. java if-else statement

2. java switch statement,

In java we basically use two conditional statements, the first one is if/else and the second one is switch statements

Watch Step by Step guide on the topic Conditional Statements in Java:

Java Code for if-else statement:

public class ConditionalStatement{

public static void main(String[] args){

int a = 10;

if(a>10){
System.out.println (“A is greater than 10”);

}
else{ System.ou.println (“A is less than or equal to 10”);}
}
}

Java Code for if-else statement:

public class ConditionalStatement{

public static void main(String[] args){

int a = 10;

if(a>10){
System.out.println (“A is greater than 10”);

}else if (a == 10){


System.out.println (“A is equals to 10”);
} else{
System.ou.println (“A is less than 10”);}
}
}

Java Code for if-else statement another one:

public class ConditionalStatement{

public static void main(String[] args){

int passmarks = 25;

if(passmarks<35){

System.out.println(“Student has failed”);

}else if (passmarks >=35){
System.out.println(“Student has passed”);}

}

}

Java Code for switch statement:

public class ConditionalStatement{

public static void main(String[] args){

int passmarks = 35;

switch(passmarks){

case 35:

System.out.println(“Value is 35”);

break;

case 40:

System.out.println(“Value is 40”);

break;

case 45:

System.out.println(“Value is 45”);

break;

default:

System.out.println(“Value is default”);

}

}

}

Connect with us:

Leave a comment

Your email address will not be published. Required fields are marked *

About Us

Providing expert blogs on web, SEO, tech, YouTube, and more, helping readers stay updated and grow in the digital world.

Email Us: contact@technicalspeaks.com

Contact: +91 7986794481

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!