instanceof java
Posts: 576
Nickname: instanceof
Registered: Jan, 2015
instanceof java is a java related one.
If Else Statment in Java
Posted: Jun 27, 2015 9:02 AM
This post originated from an RSS feed registered with Java Buzz
by instanceof java.
Original Post: If Else Statment in Java
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java
Advertisement
If statement : if statement in java is decision making statement in java. if statement will have a condition and if that condition is true then the corresponding block will be executed. if(condition){ // } If condition syntax: if(condition){ // statements } Sample program on if statement: package com.instanceofjava; import java.lang.*; public class ifExample { public static void main(String[] args) { if(true){ System.out.println("if condition executed"); } } Output: Java program to compare two numbers in java package com.instanceofjava; import java.lang.*; public class simpleIfExample {
public static void main(String[] args) { int x= 37;
int y= 37;
if (x == y) {
System .out .println ( x+ " is equal to " + y) ;
}
if (x > y) {
System .out .println ( x+ " is greater than " + y) ;
}
if (x < y) {
System .out .println ( x+ " is less than " + y) ;
}
} Output: Else Statement: if(condition){ //} else { // }Java program to compare two numbers in java using if else package com.instanceofjava; import java.lang.*; public class ifElseExample {
public static void main(String[] args) { int x= 37;
int y= 37;
if (x == y) {
System .out .println ( x+ " is equal to " + y) ;
} else if (x > y) {
System .out .println ( x+ " is greater than " + y) ;
} else{
System .out .println ( x+ " is less than " + y) ;
}
} Output: Java program to find leap year or not in java using if else package com.instanceofjava; import java.lang.*; public class ifElseExample {
public static void main(String[] args) { int year = 2015; //if year is divisible by 4, it is a leap year if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) System.out.println("Year " + year + " is a leap year"); else System.out.println( year + " is not a leap year"); } Output: Java program to find even or odd using if else statment package com.instanceofjava; import java.lang.*; public class ifElseEvenOddExample { public static void main(String[] args) { int a=10; if((a%2)==0){ System.out.println(a+"is even number"); }else{ System.out.println(a+"is odd number"); } } Output:
Read: If Else Statment in Java