PASTEBIN
| #1 paste tool since 2002
create new paste
tools
api
archive
real-time
faq
PASTEBIN
create new paste
trending pastes
sign up
login
my settings
my profile
Public Pastes
~@~@Pakistan vs En...
1 min ago
Untitled
6 sec ago
Untitled
8 sec ago
Linq-to-sql logic ...
14 sec ago
2012@@Gatorade Due...
29 sec ago
How to configure e...
20 sec ago
hotfile premium ac...
28 sec ago
Kun
25 sec ago
charly
By: a guest on Jun 19th, 2008 | syntax:
Java
| size: 0.83 KB | hits: 87 | expires: Never
download
|
raw
|
embed
|
report abuse
Copied
public
class
Palindrome
{
public
static
boolean
pal_iter
(
String
s
)
{
int
len
=
s.
length
(
)
;
for
(
int
i
=
0
;
i
<
len
/
2
;
i
++
)
if
(
s.
charAt
(
i
)
!=
s.
charAt
(
len
-
i
-
1
)
)
return
false
;
return
true
;
}
public
static
boolean
pal_recur
(
String
s
)
{
return
pal_aux
(
s,s.
length
(
)
,0
)
;
}
private
static
boolean
pal_aux
(
String
s,
int
len,
int
i
)
{
if
(
i
==
len
/
2
)
return
true
;
else
if
(
s.
charAt
(
i
)
!=
s.
charAt
(
len
-
i
-
1
)
)
return
false
;
return
pal_aux
(
s,len,i
+
1
)
;
}
public
static
void
main
(
String
...
args
)
{
System
.
out
.
println
(
"iteratif:"
)
;
System
.
out
.
println
(
pal_iter
(
"radar"
)
)
;
System
.
out
.
println
(
pal_iter
(
"osef"
)
)
;
System
.
out
.
println
(
)
;
System
.
out
.
println
(
"récursif:"
)
;
System
.
out
.
println
(
pal_recur
(
"radar"
)
)
;
System
.
out
.
println
(
pal_recur
(
"osef"
)
)
;
}
}
create a
new version
of this paste
RAW Paste Data