While Loop Example

  1. /*
  2.   While loop Example
  3.   This Java Example shows how to use while loop to iterate in Java program.
  4. */
  5.  
  6. public class SimpleWhileLoopExample {
  7.  
  8. public static void main(String[] args) {
  9.  
  10. /*
  11.   * Syntax of while loop is
  12.   *
  13.   * while( <condition> )
  14.   * <loop body>
  15.   *
  16.   * where <condition> is a boolean expression. Loop body is executed as long
  17.   * as condition is true.
  18.   *
  19.   * Loop body may contain more than one statments. In that case it should be
  20.   * enclosed in a block.
  21.   */
  22.  
  23. int i = 0;
  24.  
  25. while(i < 5)
  26. {
  27. System.out.println("i is : " + i);
  28. i++;
  29. }
  30.  
  31.  
  32. /*
  33.   * The following code will create an infinite loop, since j < 5 will always
  34.   * evaluated to true
  35.   */
  36. //int j = 0;
  37. //while(j < 5)
  38. // System.out.println("j is : " + j);
  39.  
  40.  
  41.  
  42. }
  43. }
  44.  
  45. /*
  46. Output would be
  47. i is : 0
  48. i is : 1
  49. i is : 2
  50. i is : 3
  51. i is : 4
  52. */

java program

can you post here an example of java program where there is an i/o statements, condition, looping and methods in one class only..or in one program rather..

i really do need it by saturday for my java programming subject.. i am hoping that you can help me..'
godbless

Post new comment

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

Related Java Examples



    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!