How fast will it be?



  • Is there a difference in setting speed between these codes?

    int a;
    for (int i = 0; i < x; i++){
        a = sc.nextInt();
      }
    

    and

    for (int i = 0; i < x; i++){
      int  a = sc.nextInt();
      }
    

    In the cycle, let me compare it to something. So I rewrite every time the variable in the first case, and in the second, I create a new one? Does it affect your memory?
    P.S. needs to be known for olimpiad tasks.



  • http://www.ibm.com/developerworks/ru/library/j-noaccent/#N101AB

    Don't make cycle variables.

    There is often a situation where the proclamation of variables is placed outside cycle boundaries. Such a situation could result in errors, as the variables could be accessed outside the area. areas where their application was contemplated. It's especially likely. for variables with common names, e.g. i or tmp. ♪ in particular, old values may be retained in variables and disrupted the work of the subsequent code in the most unpredictable way.

    Students with excessive optimization tend object, That this will reduce the code &apos; s productivity, as more action is taken I'll have to do it on every cycle iteration. However, redundant announcement The variable does not require any instructions. Transport in-cycle announcements will have no impact on productivity applications on the Java platform.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2