0% found this document useful (0 votes)
6 views2 pages

JavaScript & Java Interview Questions

The document contains beginner-level programming interview questions and answers for both JavaScript and Java. It includes examples of functions to reverse a string, check for prime numbers, find the largest number in an array, check for palindromes, generate Fibonacci series, and calculate factorials. Each question is accompanied by a code snippet demonstrating the solution.

Uploaded by

puratchi14vrn
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

JavaScript & Java Interview Questions

The document contains beginner-level programming interview questions and answers for both JavaScript and Java. It includes examples of functions to reverse a string, check for prime numbers, find the largest number in an array, check for palindromes, generate Fibonacci series, and calculate factorials. Each question is accompanied by a code snippet demonstrating the solution.

Uploaded by

puratchi14vrn
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Interview Programming Questions & Answers

■ Web Technologies (JavaScript)

Beginner Questions

1. Write a JavaScript program to reverse a string.


function reverseString(str) { return [Link]("").reverse().join(""); }
[Link](reverseString("hello")); // "olleh"

2. Check if a number is prime or not.


function isPrime(n) { if (n <= 1) return false; for (let i = 2; i <= [Link](n);
i++) { if (n % i === 0) return false; } return true; } [Link](isPrime(7)); //
true

3. Find the largest number in an array.


function findLargest(arr) { return [Link](...arr); }
[Link](findLargest([1, 5, 3, 9, 2])); // 9

4. Write a function to check if a string is a palindrome.


function isPalindrome(str) { let reversed = [Link]("").reverse().join("");
return str === reversed; } [Link](isPalindrome("madam")); // true

5. Print Fibonacci series up to n terms.


function fibonacci(n) { let a = 0, b = 1, result = []; for (let i = 0; i < n; i++)
{ [Link](a); [a, b] = [b, a + b]; } return result; }
[Link](fibonacci(7)); // [0,1,1,2,3,5,8]

■ Java Programming

Beginner Questions

1. Write a program to print Fibonacci series up to n.


class Fibonacci { public static void main(String[] args) { int n = 7, a = 0, b =
1; for (int i = 0; i < n; i++) { [Link](a + " "); int sum = a + b; a =
b; b = sum; } } }

2. Write a program to check if a number is Armstrong.


class Armstrong { public static void main(String[] args) { int num = 153, temp =
num, sum = 0; while (temp > 0) { int digit = temp % 10; sum += digit * digit *
digit; temp /= 10; } if (sum == num) [Link](num + " is Armstrong.");
else [Link](num + " is not Armstrong."); } }

3. Write a program to check if a string is a palindrome.


class Palindrome { public static void main(String[] args) { String str = "madam";
String rev = new StringBuilder(str).reverse().toString(); if ([Link](rev))
[Link]("Palindrome"); else [Link]("Not Palindrome"); } }

4. Find the largest element in an array.


class Largest { public static void main(String[] args) { int arr[] = {10, 20, 5,
30}; int max = arr[0]; for (int i = 1; i < [Link]; i++) { if (arr[i] > max)
max = arr[i]; } [Link]("Largest: " + max); } }

5. Write a program to calculate factorial of a number.


class Factorial { public static void main(String[] args) { int n = 5, fact = 1;
for (int i = 1; i <= n; i++) { fact *= i; } [Link]("Factorial: " +
fact); } }

You might also like