Computer Science, asked by gautamray1, 1 year ago

javascript function that checks wheather a string is palindrome or not

Answers

Answered by Tarun304
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");
}
}

Tarun304: The line marked with * will be for(int i=0; i<s.length (); i++)
Tarun304: Then write {
Tarun304: Continue the from the above
Answered by siddhartharao77
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!
Similar questions