how to Create a Java Package from MATLAB Code?

What am I doing wrong with this code?

  • This was the first case study code. package sequence1; /** * * @author Daniel */ public class Sequence1 { int firstNumber = 0; int secondNumber = 1; int nextNumber = 0; public void displaySequence() { System.out.println(firstNumber); System.out.println(secondNumber); nextNumber = secondNumber + firstNumber; while(nextNumber <= 100) { System.out.println(nextNumber); firstNumber = secondNumber; secondNumber = nextNumber; nextNumber = firstNumber + secondNumber; } } } This is the case study I am working on which said to edit the previous code. Task 2 – Modifying a while Loop to a for Loop In this task, you modify the class that you created in Exercise 1, Task 2 and replace the while loop with a for loop. Complete the following steps: 1. Create a class Sequence2 similar to Sequence1 as in Exercise 1, Task 2 and save it as Sequence2.java in your working directory. 2. Create an additional final member variable, SEQUENCE_COUNT, and assign 10 to it. Ensure that the other member variables remain unchanged. 3. In the displaySequence method, modify the while loop to a for loop such that only the first 10 values of the fibonacci series are displayed. The result should look like: 0 1 1 2 3 5 8 13 21 34. 4. Save and compile the Sequence2.java file. 5. Compile the provided Sequence2Test.java, execute it, and verify the output. This is what the code looks like when I edited it but it will not compile. package sequence2; /** * * @author Daniel */ public class Sequence2 { final int Sequence_Count = 10; int firstNumber = 0; int secondNumber = 1; int nextNumber = 0; public void displaySequence2() { System.out.println(firstNumber); System.out.println(secondNumber); nextNumber = secondNumber + firstNumber; for(nextNumber <= Sequence_Count) { System.out.println(nextNumber); firstNumber = secondNumber; secondNumber = nextNumber; nextNumber = firstNumber + secondNumber; } } } What do I need to change in the code to make it work?

  • Answer:

    ur for loop should look smthng like this.... for(nextNumber=0;nextNumber<=SEQUENCE_… nextNumber++){ // remaining code will go here. }

ska_ter3 at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Show your code && errors. = The people can help you make it work right.

You don't say what the compiler is complaining about, but this line doesn't look right: for(nextNumber <= Sequence_Count) { Check the syntax of a for-loop in your reference manual. Hope that helps.

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.