Wednesday, January 4, 2012

If Statement in JAVA



If else statement is used to execute some code only if a specified condition is true.If condition is true then the statement will be execute 

Syntax of  If Statement in JAVA

if (condition)
  {
  code to be executed if condition is true
  }

Note : if is written in only lowercase letters. If we use uppercase letter like (IF) it will give error 


Example of if statement

public class IfStatement {

 public static void main(String[] args) {
  int a = 20, b = 30;
  if (a > b)
   System.out.println("a > b");
  if (a < b)
   System.out.println("b > a");
 }
}


Output of This Example

b > a


2 comments:

  1. Please, stop wasting Internet space on re-explaining the basic language constructs. If you don't have an interesting topic to write on, don't write. Go learn a useful skill first.

    ReplyDelete
  2. Its really a nice and informative post you have shared, which is knowledgeable for most of the IT student because it is basic of programming. Thanks for sharing this post.

    subject teachers

    ReplyDelete