if ( condition ){
// code block to execute
}
condition : Check the logic and it should return true or false.
int mark=86;
if ( mark >80) {
System.out.println("More than 80");
}
Output
More than 80
boolean my_condition=true;
if( my_condition ) {
System.out.println(my_condition);
}
Output is
true
int mark=76;
if ( mark >80) {
System.out.println("More than 80");
}
else {
System.out.println("Less than 80");
}
int mark=76;
if ( mark >80) {
System.out.println("More than 80");
}
else if(mark>50) {
System.out.println("More than 50");
}
Example
int mark=46;
if ( mark >80) {
System.out.println("More than 80");
}
else if(mark>50) {
System.out.println("More than 50");
}
else {
System.out.println("Less than 50");
}
Example
int mark=46;
if ( mark >=80) {
System.out.println("80 or more");
}
else if(mark>=50) {
System.out.println("50 or more");
}
else if(mark >=30 ){
System.out.println("30 or more");
}
int i=11,j=10,k=9;
if ( j>i) {
if(j>k) {
System.out.println("Highest:" + j);
}
else {
System.out.println("Highest:" + k);
}
}
else if(i>k){
System.out.println("Highest:"+ i);
}
else {
System.out.println("Highest:" + k);
}
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.