javascript function that checks wheather a string is palindrome or not
Answers
Answered by
1
public class Palindrome
{
public void main(String s)
{
String rev="";
char ch =' ';
for(int i =0;* look at comments below. ch= s.charAt(i ); rev=ch+rev;
}
if(s.equalsIgnoreCase(rev)
System. out.print( s+ " is a Palindrome String");
else
System. out.println( s+ "is not a Palindrome String");
}
}
{
public void main(String s)
{
String rev="";
char ch =' ';
for(int i =0;* look at comments below. ch= s.charAt(i ); rev=ch+rev;
}
if(s.equalsIgnoreCase(rev)
System. out.print( s+ " is a Palindrome String");
else
System. out.println( s+ "is not a Palindrome String");
}
}
Tarun304:
The line marked with * will be for(int i=0; i<s.length (); i++)
Answered by
1
<html>
<body>
<script type="text/javascript">
function palindrome()
{
var reverse = "";
var str = document.getElementById("str").value;
var i = str.length;
for(var j=i; j>=0; j--)
{
reverse = reverse+str.charAt(j);
}
if(str == reverse)
{
alert(str+" is palindrome");
}
else
{
alert(str+" is not a palindrome");
}
}
</script>
<form>
<label>Enter a String/Number:</label>
<input type="text" id="str" name="string" />
<br/>
<input type="submit" value="Click" onclick="palindrome();"/>
</form>
</body>
</html>
Hope this helps!
<body>
<script type="text/javascript">
function palindrome()
{
var reverse = "";
var str = document.getElementById("str").value;
var i = str.length;
for(var j=i; j>=0; j--)
{
reverse = reverse+str.charAt(j);
}
if(str == reverse)
{
alert(str+" is palindrome");
}
else
{
alert(str+" is not a palindrome");
}
}
</script>
<form>
<label>Enter a String/Number:</label>
<input type="text" id="str" name="string" />
<br/>
<input type="submit" value="Click" onclick="palindrome();"/>
</form>
</body>
</html>
Hope this helps!
Similar questions