If-else Statement in Java




If block contains the condition, if condition is true, then the statements of if block will execute and if the condition is false then the statement of else block will execute.

Syntax :

if(boolean_expression) {
   /* statement(s) will execute if the boolean expression is true */
} else {
   /* statement(s) will execute if the boolean expression is false */
}               

Block Diagram :

prowessapps.in

Example:

WAP to check no. is +ive or -ive.
import java.util.Scanner;
class Test
{
 public static void main(String []arg)
 {
  Scanner sc;
  sc = new Scanner(System.in);
  int x ;
  System.out.print("Enter any number: ");
  x = sc.nextInt();
 if(x>=0) {
  System.out.print("X is Positive");
 }
 else {
   System.out.print("X is Negative");
  }
 } // main closed
}// class closed
OUTPUT 1:
Enter any number: 12
X is Positive
OUTPUT 2:
Enter any number: -12
X is Negative

Next topic is if-else ladder statement




 







Training For College Campus

We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.

Please mail your requirement at info@prowessapps.in


Projects For Students

Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.

Students can mail requirement at info@prowessapps.in



CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-8527238801 , +91-9451396824

© 2017, prowessapps.in, All rights reserved