If Else statement Example

  1. /*
  2.   If Else statement Example
  3.   This Java Example shows how to use if else statement in Java program.
  4. */
  5.  
  6.  
  7. public class SimpleIfElseStatementExample {
  8.  
  9. public static void main(String[] args) {
  10.  
  11. /*
  12.   * If else statement is used to execute either of two conditions based
  13.   * upon certain condition.
  14.   * Syntax of if else statement is,
  15.   *
  16.   * if(<condition>)
  17.   * statement1
  18.   * else
  19.   * statement2
  20.   *
  21.   * where <condition> is a boolean expression.
  22.   * If <condition> is true, statement1 will be executed, else statement2 will
  23.   * be executed.
  24.   */
  25.  
  26. int i = 0;
  27.  
  28. if(i == 0)
  29. System.out.println("i is 0");
  30. else
  31. System.out.println("i is not 0");
  32. }
  33. }
  34.  
  35. /*
  36. Output would be
  37. i is 0
  38. */

i love java

how to use if else statement by making a pingpong games.

hi there

uhmm...how can you compare 4 different statements using if else...that was exam yesterday... and i wasn't able to answer it...please help me...thanks a lot...the problem was.... making a program that would show numbers if they are odd or even and if they are negative or a positive odd/even number...the condition is...input a positive or negative number...numbers range from -100 to 0 and 0 to +100

Post new comment

To combat spam, please enter the code in the image.


Suggested Reading

Oracle Magazine
Contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more.
Cost: FREE

View/Subscribe
NASA Tech Briefs
Features exclusive reports of innovations developed by NASA and its industry partners/contractors that can be applied to develop new/improved products and solve engineering or manufacturing problems.
Cost: FREE

View/Subscribe
FierceBiotech IT
Is a free, easy to read weekly email service that brings must read biotech IT news to senior biotech, pharma, and IT executives.
Cost: FREE

View/Subscribe
Simply SQL
Simply SQL is a practical step-by-step guide to writing SQL.
Cost: FREE

View/Subscribe
Simply JavaScript
Packed with full-color examples, Simply JavaScript is all you need to start programming in JavaScript the right way.
Cost: FREE

View/Subscribe
PCMag.com's What's New Now
Lance Ulanoff, Editor in Chief of the PC Magazine Network, brings you this twice-weekly roundup of the latest top tech stories, the best new product reviews, plus special offers from Ziff Davis and its partners.
Cost: FREE

View/Subscribe

Could not find what you are looking for? Search Java Examples




Feel Tired? Read Jokes & Inspirational Stories, Play Games!