Moksha - Test 4
Moksha - Test 4 - Core Java
Duration: 90 minutes
Total Score: 100 points
Instructions:
- This coding test consists of 10 programming questions.
- Each question is worth 10 points.
- You have 90 minutes to complete the test.
- Write Java code for each question.
- Ensure your code is well-documented and follows best practices.
- Please write the code in the space provided.
Question 1: Fibonacci Series (10 points) Write a Java program to print the Fibonacci series up to a specified number of terms.
Algorithm:
- Initialize variables
a
,b
, andsum
to 0, 1, and 0, respectively. - Print the initial values of
a
andb
. - Use a loop to generate the Fibonacci series:
- Set
sum
to the sum ofa
andb
. - Update
a
to the value ofb
. - Update
b
to the value ofsum
. - Print the value of
sum
.
- Set
- Repeat the loop for the specified number of terms.
- Question 2: Armstrong Number (10 points)
Write a Java program to check if a given number is an Armstrong number or not.
Algorithm:
- Read the input number.
- Calculate the number of digits in the input number.
- Initialize a variable
temp
to store a temporary copy of the input number. - Initialize a variable
sum
to 0. - Use a loop to extract each digit from
temp
:- Calculate the
digit^numberOfDigits
for each digit. - Add the result to
sum
.
- Calculate the
- Check if
sum
is equal to the input number.- If equal, it's an Armstrong number; otherwise, it's not.
- Question 3: Prime Numbers (10 points)
Write a Java program to find and print all prime numbers within a given range.
Algorithm:
- Read the lower and upper bounds of the range.
- Initialize a variable
isPrime
to true. - Use a loop to iterate through numbers within the range:
- For each number, check if it's prime:
- Start a loop from 2 to the square root of the number.
- If the number is divisible by any value in that range, set
isPrime
to false and break.
- If
isPrime
is still true, print the number.
- For each number, check if it's prime:
Question 4: Nth Element of Array (10 points) Write a Java program to find the Nth element of an array of integers.
Algorithm:
- Read the array of integers.
- Read the value of
N
. - Check if
N
is within a valid range (0 to array length - 1). - If
N
is valid, print the element at indexN
.
Question 5: Pattern Printing (10 points) Write a Java program to print the following pattern:
Algorithm:
- Use nested loops to iterate through rows and columns.
- In the inner loop, print the column number if it's less than or equal to the row number.
Question 6: Array Sum (10 points) Write a Java program to find the sum of all elements in an array of integers.
Algorithm:
- Read the array of integers.
- Initialize a variable
sum
to 0. - Use a loop to iterate through the elements of the array:
- Add each element to
sum
.
- Add each element to
sum
now contains the sum of elements.- Question 7: String Reverse (10 points)
Write a Java program to reverse a string without using any library function.
Algorithm:
- Read the input string.
- Initialize an empty string
reverseStr
. - Use a loop to iterate through the characters of the input string from the end to the beginning:
- Append each character to
reverseStr
.
- Append each character to
reverseStr
now contains the reversed string.- Question 8: Factorial (10 points)
Write a Java program to find the factorial of a given number using recursion.
Algorithm:
- Read the input number.
- Create a recursive function
calculateFactorial
that takes an integer parametern
. - In the function:
- If
n
is 0 or 1, return 1 (base case). - Otherwise, return
n * calculateFactorial(n - 1)
.
- If
- Call
calculateFactorial
with the input number to compute the factorial.// Your code for Question 8 here:
Question 9: Array Rotation (10 points) Write a Java program to rotate an array to the left by a specified number of positions.
Algorithm:
- Read the array of integers.
- Read the number of positions to rotate (
k
). - Create a temporary array of the same size as the original array.
- Copy the elements of the original array to the temporary array with an offset of
k
. - Copy the remaining elements from the original array to the temporary array.
- The temporary array now contains the rotated elements.
Question 10: Palindrome (10 points) Write a Java program to check if a given string is a palindrome.
Algorithm:
- Read the input string.
- Initialize two pointers, one at the beginning and one at the end of the string.
- Use a loop to compare characters at the two pointers:
- If they are equal, move the pointers toward each other.
- If any pair of characters doesn't match, it's not a palindrome.
- If the loop completes without finding any non-matching pair, it's a palindrome.
Question 11: Simple Calculator (10 points) Write a Java program to implement a simple calculator that performs addition, subtraction, multiplication, and division based on user input.
Algorithm:
- Read two numbers and an operator (+, -, *, /) from the user.
- Perform the corresponding arithmetic operation and print the result.
Question 12: Multiplication Table (10 points) Write a Java program to print the multiplication table for a given number (up to a specified range).
Algorithm:
- Read the number and the range from the user.
- Use nested loops to generate the multiplication table for the number within the specified range.
Question 13: Armstrong Number Pattern (10 points) Write a Java program to print all Armstrong numbers in a specified range, along with their digits.
Algorithm:
- Read the lower and upper bounds of the range from the user.
- Use a loop to iterate through numbers within the range.
- For each number, calculate the sum of its digits raised to the power of their count.
- Check if the sum is equal to the number itself (Armstrong number).
- If it's an Armstrong number, print the number and its individual digits.
Question 14: Diamond Pattern (10 points) Write a Java program to print a diamond pattern of asterisks (*) based on user input for the number of rows.
Algorithm:
- Read the number of rows (an odd number) from the user.
- Use nested loops to print the diamond pattern:
- In the first half of the pattern, print spaces and asterisks.
- In the second half of the pattern, reverse the printing.
Question 15: Factorial Pattern (10 points) Write a Java program to print a factorial pattern for a given number.
Algorithm:
- Read the number from the user.
- Use a loop to generate the factorial pattern:
- In each row, print the factorials of numbers from 1 to the row number.
Note: Make sure to include the necessary import statements and provide appropriate comments for each code segment. Good luck with the test!
-------------------------------------------------------------------------------------------------------
Moksha - Test 4 - Reasoning & Aptitude
Moksha - Test 4 - HTML
1.
How can you integrate CSS on a web page?
2. How to create mail link in HTML,How
do you make a clickable link in a phone number?
3. What are two types of Web Storage
in HTML5?
4. How do you insert a copyright
symbol on a browser page and also write numerical entity?
5. Is there any way to keep list
elements straight in an HTML file?
6. How do you create multicolored text
in a webpage?
7.
Write an HTML table tag sequence that outputs the following:
70 pcs 200 600, 20 pcs 15 70
8.
Briefly describe the correct usage of the following HTML5 semantic
elements: <header>, <article>, <section>, <footer>.
9.
What is <figure> in HTML5?What is figurecation?
10. Can a single text link point to
two different web pages?
11. Can you change the color of
bullets?
12.
What happens if you open the external CSS file in a browser?
13.
What happens if the list-style-type property is used on a non-list
element like a paragraph?
14. Which browsers support HTML5?Name
two new tags included in the HTML 5?'
15. Can several selectors with class
names be grouped together?
16. What are the new FORM elements
which are available in HTML5?
17.What other ways can be used to
align images and wrap text?
18. Can a <section> contain
<article> elements? Can an <article> contain <section>
elements? Provide usage examples.
19. What are some of the common lists
that can be used when designing a page?
Moksha - Test 4 - Soft skills
Soft skills 25
Marks 45
mins
A). WRITE ANY THREE QUESTIONS FROM THE
FOLLOWING 3*5=15
1). Write
about phone etiquette and mail etiquette?
2). Share
your thoughts about a movie that you liked a lot?
3). Explain
time management and teamwork?
4). Use
following corporate jargon in a sentence?
Out of shape looking blue go for the extra mile burn the midnight oil
B).
MATCH THE FOLLOWING
5*1=5
1. Mean Imperfection
or bend of an object
2. Arrogant Mix-up
in a messy way
3. Dream boat Rude
4. Tangle Wish
5. Dent Proud
C). FILL
IN THE BLANKS WITH PROPER ANSWERS
5*1=5
1). Do you
_ if I take your pen? Hope you _.
2). I _
neither my friend _ his brother.
3). The sky
is _ high _ touch.
4). _ of
raining she _ outside.
5). I _
others _ though they don’t give it back.
Comments
Post a Comment