0% found this document useful (0 votes)
45 views2 pages

Computer Class Notes 2

This document contains examples of different types of comments in Java code, including single-line, multi-line, Javadoc, and method comments. It also provides an example class that calculates Fibonacci numbers using memoization to improve performance. The main method calls the fibonacci method to calculate and print the 12th Fibonacci number.

Uploaded by

Jagrit Churiwala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views2 pages

Computer Class Notes 2

This document contains examples of different types of comments in Java code, including single-line, multi-line, Javadoc, and method comments. It also provides an example class that calculates Fibonacci numbers using memoization to improve performance. The main method calls the fibonacci method to calculate and print the 12th Fibonacci number.

Uploaded by

Jagrit Churiwala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

// This is an example of a single line

comment using two slashes

/*
* This is an example of a multiple line
comment using the slash and asterisk.
* This type of comment can be used to hold a
lot of information or deactivate
* code, but it is very important to remember
to close the comment.
*/

package fibsandlies;

import java.util.Map;
import java.util.HashMap;

/**
* This is an example of a Javadoc comment;
Javadoc can compile documentation
* from this text. Javadoc comments must
immediately precede the class, method,
* or field being documented.
* @author Wikipedia Volunteers
*/
public class FibCalculator extends Fibonacci
implements Calculator {
private static Map<Integer, Integer>
memoized = new HashMap<>();

/*
* The main method written as follows is
used by the JVM as a starting point
* for the program.
*/
public static void main(String[] args) {
memoized.put(1, 1);
memoized.put(2, 1);
System.out.println(fibonacci(12)); //
Get the 12th Fibonacci number and print to
console
}

/**
* An example of a method written in
Java, wrapped in a class.
* Given a non-negative number FIBINDEX,
returns
* the Nth Fibonacci number, where N
equals FIBINDEX.
*
* @param fibIndex The index of the
Fibonacci number
* @return the Fibonacci number
*/
public static int fibonacci(int fibIndex)
{
if (memoized.containsKey(fibIndex))
return memoized.get(fibIndex);
else {
int answer = fibonacci(fibIndex -
1) + fibonacci(fibIndex - 2);
memoized.put(fibIndex, answer);
return answer;
}
}
}

You might also like