This Program Illustrates How Loops Can Be Nested Into Each Other

This Program Illustrates How Loops Can Be Nested Into Each Other

<p>// ******************************************************************* // Statements13.java By: Aiman Hanna (C) 1993 - 2016 // This program illustrates how loops can be nested into each other. // // Key Points: // 1) Nested Loops // ******************************************************************* import java.util.Scanner; public class Statements13 {</p><p> public static void main(String[] args) {</p><p>// This program will draw series of stars to the user. // The size of these stars will be provided by the user // and must be within a specified range </p><p> int i, j, sz;</p><p>// Create a scanner objects Scanner kb = new Scanner(System.in);</p><p>System.out.print ("Please Enter a Value between 1 & 15 for the Stars Size: "); sz = kb.nextInt();</p><p> while (sz < 1 || sz > 15) { System.out.print ("Invalid Value. Please Enter a Value between 1 & 15: "); sz = kb.nextInt();</p><p>}</p><p> for (i = 1; i <=sz; i++ ) // go for "sz" lines { for (j = 1; j <=i; j++) // go for as many "i"s { System.out.print ("*"); } System.out.println(); // now go to the next line }</p><p> kb.close();</p><p>}</p><p>}</p><p>/* The Output</p><p>Please Enter a Value between 1 & 15 for the Stars Size: 29 Invalid Value. Please Enter a Value between 1 & 15: -8 Invalid Value. Please Enter a Value between 1 & 15: 0 Invalid Value. Please Enter a Value between 1 & 15: 14 * ** *** **** ***** ****** ******* ******** ********* ********** *********** ************ ************* **************</p><p>*/</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us