Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
m3104-tp4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Amaury Vanoorenberghe
m3104-tp4
Commits
0501bedb
Commit
0501bedb
authored
3 years ago
by
Amaury Vanoorenberghe
Browse files
Options
Downloads
Patches
Plain Diff
EX - Ajout de la servlet Fibonacci.java
parent
fa1a1cfe
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Fibonacci.java
+48
-0
48 additions, 0 deletions
src/Fibonacci.java
with
48 additions
and
0 deletions
src/Fibonacci.java
0 → 100644
+
48
−
0
View file @
0501bedb
import
java.io.*
;
import
java.util.*
;
import
javax.servlet.*
;
import
javax.servlet.http.*
;
import
javax.servlet.annotation.WebServlet
;
@WebServlet
(
"/Fibonacci"
)
public
class
Fibonacci
extends
HttpServlet
{
public
void
service
(
HttpServletRequest
req
,
HttpServletResponse
res
)
throws
ServletException
,
IOException
{
res
.
setContentType
(
"text/html;charset=UTF-8"
);
PrintWriter
out
=
res
.
getWriter
();
out
.
println
(
"<head><title>Fibonacci</title>"
);
out
.
println
(
"<META content=\"charset=UTF-8\"></head><body>"
);
out
.
println
(
"<center>Fibonacci</center><p>"
);
FibonacciSequence
seq
=
new
FibonacciSequence
();
for
(
int
x
=
0
;
x
<=
30
;
++
x
)
{
int
y
=
seq
.
get
(
x
);
out
.
println
(
String
.
format
(
"<span><b>f(%d)</b> = %d</span><br/>"
,
x
,
y
));
}
out
.
println
(
"</p>"
);
}
private
class
FibonacciSequence
{
private
Map
<
Integer
,
Integer
>
CACHE
=
new
HashMap
<
Integer
,
Integer
>();
public
int
get
(
int
n
)
{
if
(
n
<=
1
)
return
n
;
if
(
CACHE
.
containsKey
(
n
))
{
return
CACHE
.
get
(
n
);
}
int
a
=
get
(
n
-
1
);
int
b
=
get
(
n
-
2
);
int
x
=
a
+
b
;
CACHE
.
put
(
n
,
x
);
return
x
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment