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:

  1. Initialize variables a, b, and sum to 0, 1, and 0, respectively.
  2. Print the initial values of a and b.
  3. Use a loop to generate the Fibonacci series:
    • Set sum to the sum of a and b.
    • Update a to the value of b.
    • Update b to the value of sum.
    • Print the value of sum.
  4. Repeat the loop for the specified number of terms.

  5. Question 2: Armstrong Number (10 points)

Write a Java program to check if a given number is an Armstrong number or not.

Algorithm:

  1. Read the input number.
  2. Calculate the number of digits in the input number.
  3. Initialize a variable temp to store a temporary copy of the input number.
  4. Initialize a variable sum to 0.
  5. Use a loop to extract each digit from temp:
    • Calculate the digit^numberOfDigits for each digit.
    • Add the result to sum.
  6. 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:

  1. Read the lower and upper bounds of the range.
  2. Initialize a variable isPrime to true.
  3. 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.

Question 4: Nth Element of Array (10 points) Write a Java program to find the Nth element of an array of integers.

Algorithm:

  1. Read the array of integers.
  2. Read the value of N.
  3. Check if N is within a valid range (0 to array length - 1).
  4. If N is valid, print the element at index N.

Question 5: Pattern Printing (10 points) Write a Java program to print the following pattern:

Algorithm:

  1. Use nested loops to iterate through rows and columns.
  2. 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:

  1. Read the array of integers.
  2. Initialize a variable sum to 0.
  3. Use a loop to iterate through the elements of the array:
    • Add each element to sum.
  4. sum now contains the sum of elements.

  5. Question 7: String Reverse (10 points)

Write a Java program to reverse a string without using any library function.

Algorithm:

  1. Read the input string.
  2. Initialize an empty string reverseStr.
  3. Use a loop to iterate through the characters of the input string from the end to the beginning:
    • Append each character to reverseStr.
  4. reverseStr now contains the reversed string.

  5. Question 8: Factorial (10 points)

Write a Java program to find the factorial of a given number using recursion.

Algorithm:

  1. Read the input number.
  2. Create a recursive function calculateFactorial that takes an integer parameter n.
  3. In the function:
    • If n is 0 or 1, return 1 (base case).
    • Otherwise, return n * calculateFactorial(n - 1).
  4. 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:

  1. Read the array of integers.
  2. Read the number of positions to rotate (k).
  3. Create a temporary array of the same size as the original array.
  4. Copy the elements of the original array to the temporary array with an offset of k.
  5. Copy the remaining elements from the original array to the temporary array.
  6. 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:

  1. Read the input string.
  2. Initialize two pointers, one at the beginning and one at the end of the string.
  3. 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.
  4. 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:

  1. Read two numbers and an operator (+, -, *, /) from the user.
  2. 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:

  1. Read the number and the range from the user.
  2. 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:

  1. Read the lower and upper bounds of the range from the user.
  2. Use a loop to iterate through numbers within the range.
  3. For each number, calculate the sum of its digits raised to the power of their count.
  4. Check if the sum is equal to the number itself (Armstrong number).
  5. 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:

  1. Read the number of rows (an odd number) from the user.
  2. 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:

  1. Read the number from the user.
  2. 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


I. Choose the correct answer 25 × 1 = 25


1. A person crosses a 600 m long street in 5 minutes. What is his speed in km per hour? 
A. 3.6 B. 7.2 C. 8.4 D. 10 

2. If a person walks at 14 km/hr instead of 10 km/hr, he would have walked 20 km more. The actual distance travelled by him is: 
A. 50 km B. 56 km C. 70 km D. 80 km 

3. Excluding stoppages, the speed of a bus is 54 kmph and including stoppages, it is 45 kmph. For how many minutes does the bus stop per hour? 
A. 9 B. 10 C. 12 D. 20 

4. A man complete a journey in 10 hours. He travels first half of the journey at the rate of 21 km/hr and second half at the rate of 24 km/hr. Find the total journey in km.
 A. 220 km B. 224 km C. 230 km D. 234 km 

5. The ratio between the speeds of two trains is 7 : 8. If the second train runs 400 km in 4 hours, then the speed of the first train is: 
A. 70 kmph B.75 kmph C.84 kmph D.87.5 kmph 

6. In covering a distance of 30 km, Abhay takes 2 hours more than Sameer. If Abhay doubles his speed, then he would take 1 hour less than Sameer. Abhay's speed is: 
A. 5 kmph B. 6 kmph C. 6.25 kmph D.7.5 kmph 

7. It takes eight hours for a 600 km journey, if 120 km is done by train and the rest by car. It takes 20 minutes more, if 200 km is done by train and the rest by car. The ratio of the speed of the train to that of the cars is: 
A. 2 : 3 B. 3 : 2 C. 3 : 4 D. 4 : 3 

8. A farmer travelled a distance of 61 km in 9 hours. He travelled partly on foot @ 4 km/hr and partly on bicycle @ 9 km/hr. The distance travelled on foot is: 
A. 14 km B. 15 km C. 16 km D. 17 km 

9. Robert is travelling on his cycle and has calculated to reach point A at 2 P.M. if he travels at 10 kmph, he will reach there at 12 noon if he travels at 15 kmph. At what speed must he travel to reach A at 1 P.M.? 
A. 8 kmph B. 11 kmph C. 12 kmph D.14 kmph 

10.Vivek and Bharath go home daily after Office by an Office Cab which has a Speed of 40 kmph. Vivek takes 20% more Time than Bharath to reach his home. If Bharath’s house is at a Distance of 30 km from the office, then calculate the Distance of Vivek’s house from the office. 
A. 36 km B. 40 km C. 45 km D. 42 km 

11. One day Prakash started late for office by 1 hour, so he increased his normal Speed by 5 km/hr so that he reaches on Time. Find the normal Time taken to reach his office if his office is at a distance of 60 km from his house 
A. 3 hrs B. 5 hrs C. 6 hrs D. 4 hrs 

12. Amar, Akbar and Anthony ran on a racetrack, with Amar finishing 160 m ahead of Akbar and 400 m ahead of Anthony. Akbar finished the race 300 m ahead of Anthony. The three of them ran the entire Distance with their respective constant Speeds. What was the length of the racetrack?. 
A. 600m B. 800m C. 1000m D. 500m 

13. A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train? A. 120 m B. 180 m C. 324 m D. 150 m 

14. A train 125 m long passes a man, running at 5 km/hr in the same direction in which the train is going, in 10 seconds. The speed of the train is: 
A. 45 km/hr B. 50 km/hr C. 54 km/hr D. 55 km/hr 

15. The length of the bridge, which a train 130 metres long and travelling at 45 km/hr can cross in 30 seconds, is: A. 200 m B. 225 m C. 245 m D. 250 m 

16. A train passes a station platform in 36 seconds and a man standing on the platform in 20 seconds. If the speed of the train is 54 km/hr, what is the length of the platform? 
A. 120 m B. 240 m C. 300 m D. None 

17. A train overtakes two persons walking along a railway track. The first one walks at 4.5 km/hr. The other one walks at 5.4 km/hr. The train needs 8.4 and 8.5 seconds respectively to overtake them. What is the speed of the train if both the persons are walking in the same direction as the train?
A. 66 km/hr B. 72 km/hr C. 78 km/hr D. 81 km/hr 

18. How many seconds will a 500 metre long train take to cross a man walking with a speed of 3 km/hr in the direction of the moving train if the speed of the train is 63 km/hr? 
A. 25 B. 30 C. 40 D. 45 

19. Two goods train each 500 m long, are running in opposite directions on parallel tracks. Their speeds are 45 km/hr and 30 km/hr respectively. Find the time taken by the slower train to pass the driver of the faster one. 
A. 12 sec B. 24 sec C. 48 sec D. 60 sec 

20. Two trains of equal lengths take 10 seconds and 15 seconds respectively to cross a telegraph post. If the length of each train be 120 metres, in what time (in seconds) will they cross each other travelling in opposite direction? 
A. 10 B. 12 C. 15 D. 

20 21. A train 108 m long moving at a speed of 50 km/hr crosses a train 112 m long coming from opposite direction in 6 seconds. The speed of the second train is: 
A. 48 km/hr B. 54 km/hr C. 66 km/hr D. 82 km/hr 

22. A train moves past a telegraph post and a bridge 264 m long in 8 seconds and 20 seconds respectively. What is the speed of the train? 
A. 69.5 km/hr B. 70 km/hr C. 79 km/hr D.79.2 km/hr 

23. A train 360 m long is running at a speed of 45 km/hr. In what time will it pass a bridge 140 m long? A. 40 sec B. 42 sec C. 45 sec D. 48 sec 

24. A jogger running at 9 kmph alongside a railway track in 240 metres ahead of the engine of a 120 metres long train running at 45 kmph in the same direction. In how much time will the train pass the jogger? 
A. 3.6 sec B. 18 sec C. 36 sec D. 72 sec 

25. A 270 metres long train running at the speed of 120 kmph crosses another train running in opposite direction at the speed of 80 kmph in 9 seconds. What is the length of the other train? 
A. 230 m B. 240 m C. 260 m D. 320 m


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

Popular posts from this blog

FrontEnd - FAQs - Part 1

Java Script - FAQs

CoreJava - ClassesObjectsMethods - Assignment