Friday 15 August 2014

java - 'While' Loop not executing? -


There is a comment in my code that explains the direction in which direction I am going, but please do not answer Let me know how I can achieve that goal during answering this question.

Actually, I have an Intel label labeled "currentNum", which is equal to 1. I have a time loop, until it does not start, at least 4 million However, the loop is not being executed for some reason. While all things outside of the loop are executed, but when the loop is not there.

'Lo' is displayed once on the 'HI' console, 'Loop' has not been displayed in the console.

Code:

  / * In Fibonacci sequence each new word is generated by adding the previous two words. * Starting with 1 and 2, the first 10 words will be: * 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... * Considering the rules of the Fibonacci sequence, whose Do not exceed the value of four lakhs; * Get even the sum of the valuable posts. * / Public class solution {public static zero main (string agr []) {int lastNum1 = 0; Int lastNum2 = 0; Int currentMevan = 0; Int present = 1; Int sumEven = 0; Boolean final = true; Println ("HI"); While (Current News & lt; 4000000); Println ("loop"); CurrentNum = CurrentName + (Final No-1 + Final No 2); If (last) {lastNum1 = currentNum; Final =! Final; } Else {lastNum2 = currentNum; Final =! Final; } If (current no. 2 == 0) {currentNumEven = currentNum; SumEven + = currentNum; Println (currentNumEven); Println (currentNum); } If (Current News & lt; 4000000) {currentNum ++; } Else {System.out.println ("The sum of the Fibonacci values ​​of all:" + sumEven + "\ n Number of orders below 4,000,000 even" + CurrentNewen "); }}}}    

Error in this line:

  While (Current News & lt; 4000000);   

that last ; is the wrong place! After the condition, you should put an opening {, and then another } at the end of the loop to close the block, like this :

  while (currentM <4000000) {// body}    

No comments:

Post a Comment