The two ideas are printed from 0 to 100, and the idea 0 prints 100.

Source: Internet
Author: User

The two ideas are printed from 0 to 100, and the idea 0 prints 100.
1 public static void main (String [] args) {2 int n= 100; 3 PrinterN (N); 4} 5 6 private static void PrinterN (int N) {7 for (int I = 0; I <= n; I ++) {8 System. out. println (I); 9} 10} print 1 public static void main (String [] args) {2 int N = 100; 3 PrinterN (N ); 4} 5 6 private static void PrinterN (int n) {7 if (n> = 0) {8 PrinterN (n-1); 9 System. out. println (n); 10} 11} recursively print

However, when Recursive Implementation is used, when n exceeds 100000, an error occurs in java. lang. StackOverflowError.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.