Posts

Showing posts from 2020

Write program in JavaScript to print Fibonacci series up to 15 Observations

Fibonacci series in  JavaScript var limit = prompt("Enter the limit 'n' to generate the Fibonacci  series:", " "); var f1=0; var f2=1; document.write("The limit entered to generate the Fibonacci  series is: ",limit, "<br/>"); document.write("The Fibonacci  series is: "); document.write("",f1," "); document.write("",f2," ");   var i,f3; for(i=2; i<limit; i++) { f3=f1+f2; document.write("",f3,", "); f1=f2; f2=f3; } OutPut : The limit entered to generate the Fibonacci series is: 20 The Fibonacci series : 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 The limit entered to generate the Fibonacci series is: 15 The Fibonacci series : 0 1 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377,

Palindrome program in Java using BufferedReader

import java.io.*; class Test { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("\nEnter a String : "); String str = br.readLine(); String rev = ""; int n = str.length(); for(int i=n-1 ; i>=0 ; i--) { rev = rev + str.charAt(i); } if(str.equals(rev)) System.out.println("\nGiven string is a palindrome"); else System.out.println("\nGiven string is not a palindrome"); } } Output 1 Enter a String : ABCDDCBA Given string is a palindrome Output 2 Enter a String : abcdabcd Given string is not a palindrome