11/8/11

Problem No.1

The below program is hideously slow. CAN YOU SPOT THE REASON?

public static void main(String args[]){
      Long sum=0L;
      for ( long i=0; i < Integer.MAX_VALUE; i++){
          sum += i;
      }
      System.out.println(sum);
}





[Click for answer]


SHARE THIS POST:

Related Posts:

  • Problem No.1 The below program is hideously slow. CAN YOU SPOT THE REASON? public static void main(String args[]){ Long sum=0L; for ( long i=0; i < Integer.MAX_VALUE; i++){ sum += i; } System.out.pri… Read More
  • Problem Set 3 The below questions are very interesting and amazing questions. So please do try it. QUESTION 1 int a=5,*b=&a;printf("%d",a**b); !-- google_ad_client = "ca-pub-0770336576285658"; /* inside post */ goog… Read More
  • Java Problem Set 2 Write a function which calculates the sum of even Fibonacci numbers. public static void main(String args[]) { for(int i=1;i<22;i++) System.out.print(sumofEvenFibonacci(i) + " "); } public static long sumofE… Read More
  • Find the largest sum in an Array Problem $(document).ready(function(){ $(".flip").click(function(){ $(".panel").slideToggle("slow"); }); }); div.panel,p.flip { margin:0px; padding:5px; text-align:center; background:#e5eecc; border:solid 1px #c3c3c3; … Read More
  • Problem Set Java  Predict the Output    Question 1 class Base { public void Print() { System.out.println("Base"); } } class Derived extends Base { public void Print() { System.out.println("D… Read More