Moksha - Test 5

 




Moksha - Test 5

 Instructions:

  • Time Allowed: 3 hrs.
  • Attempt all questions.
  • Write your code in the paper provided, the same would be asked to copy into the machine and he
  • Ensure your code is well-documented and follows Java syntax and have proper comments wherever needed.
  • If you encounter any issues or have questions, raise your hand and wait for assistance.

Question 1: Check if a vowel is present in a string (5 marks)

Write a Java program that checks if a given string contains at least one vowel.

Algorithm:

  1. Initialize a boolean variable hasVowel to false.
  2. Iterate through each character in the input string.
  3. Check if the character is a vowel ('a', 'e', 'i', 'o', 'u' or their uppercase counterparts).
  4. If a vowel is found, set hasVowel to true and break the loop.
  5. Finally, return the value of hasVowel.

Question 2: Check if the given number is a prime number (10 marks)

Create a Java program to determine whether a given number is prime.

Algorithm:

  1. If the input number is less than 2, it's not prime.
  2. Iterate from 2 to the square root of the input number.
  3. If any number in this range divides the input number evenly, it's not prime.
  4. Otherwise, it's prime.

 Question 3: Print a Fibonacci sequence using recursion (10 marks)

Implement a Java program to print the Fibonacci sequence using recursion.

Algorithm:

  1. Create a recursive function fibonacci(n) that returns the nth Fibonacci number.
  2. The base cases are fibonacci(0) = 0 and fibonacci(1) = 1.
  3. For other values, use recursion: fibonacci(n) = fibonacci(n-1) + fibonacci(n-2).

Question 4: Reverse a string in Java (5 marks)

Write a Java program to reverse a given string.

Algorithm:

  1. Initialize an empty string reversed.
  2. Iterate through the input string from the end to the beginning.
  3. Append each character to reversed.
  4. Finally, reversed will contain the reversed string.

Question 5: Swap two numbers without using a third variable in Java (5 marks)

Create a Java program that swaps the values of two variables without using a third variable.

Algorithm:

  1. Use arithmetic operations to swap the values.
  2. Example: If a and b are the variables, you can swap them as follows:

cssCopy code

a = a + b; b = a - b; a = a - b;  


 Question 6: Check if a list of integers contains only odd numbers in Java (10 marks)

Write a Java program that checks if all elements in a list of integers are odd.

Algorithm:

  1. Iterate through the list.
  2. Check if each element is odd (i.e., not divisible by 2).
  3. If any element is even, return false. Otherwise, return true at the end of the loop.

Question 7: Remove spaces from a string in Java (5 marks)

Create a Java program to remove all spaces from a given string.

Algorithm:

  1. Initialize an empty string result.
  2. Iterate through the input string.
  3. If the character is not a space, append it to result.
  4. result will contain the string without spaces.

Question 8: Remove leading and trailing spaces from a string in Java (5 marks)

Write a Java program to remove leading and trailing spaces from a given string.

Algorithm:

  1. Use the trim() method to remove leading and trailing spaces from the string.

Question 9: Sort an array in Java (10 marks)

Implement a Java program to sort an array of integers in ascending order.

Algorithm:

  1. Use a sorting algorithm like bubble sort, selection sort, or Arrays.sort().

Question 10: Factorial of an integer in Java (5 marks)

Create a Java program to calculate the factorial of a given integer.

Algorithm:

  1. Use a loop to multiply all integers from 1 to the given number.

Question 11: Check if two arrays contain the same elements (10 marks)

Write a Java program that checks if two arrays contain the same elements.

Algorithm:

  1. Compare the lengths of the two arrays. If they are not equal, return false.
  2. Sort both arrays.
  3. Iterate through the arrays and compare each element. If any pair of elements differs, return false. Otherwise, return true.

Question 12: Sum of all elements in an integer array in Java (5 marks)

Implement a Java program to calculate the sum of all elements in an integer array.

Algorithm:

  1. Initialize a variable sum to 0.
  2. Iterate through the array and add each element to sum.

Question 13: Shuffle an array in Java (10 marks)

Create a Java program to shuffle the elements of an array.

Algorithm:

  1. Use the Fisher-Yates shuffle algorithm to randomly permute the elements in the array.

Question 14: Find the second-highest number in an array (10 marks)

Write a Java program that finds the second-highest number in an array of integers.

Algorithm:

  1. Initialize two variables, max and secondMax, to the smallest integer value.
  2. Iterate through the array and update max and secondMax accordingly.

 

Question 15: Remove all occurrences of a given character from an input string in Java (5 marks)

Implement a Java program to remove all occurrences of a given character from an input string.

Algorithm:

  1. Iterate through the string and build a new string without the specified character.

Question 16: Check whether a string is a palindrome in Java (5 marks)

Create a Java program that checks if a given string is a palindrome (reads the same forwards and backwards).

Algorithm:

  1. Compare the characters from the beginning and end of the string, moving towards the center.

Question 17: Show a NullPointerException (5 marks)

Write Java code that intentionally triggers a NullPointerException.


Question 18: Check Armstrong number in Java (5 marks)

Implement a Java program to check if a given number is an Armstrong number.

Algorithm:

  1. Calculate the sum of cubes of its digits and check if it's equal to the original number.

Question 19: Count the digits in a number (5 marks)

Create a Java program to count the number of digits in a given number.

Algorithm:

  1. Convert the number to a string and count the characters.

 Question 20: Calculate the number of times a digit ‘D’ appears in a number N (10 marks)

Write a Java program that takes two inputs, a number N and a digit D, and calculates how many times the digit D appears in N.

Algorithm:

  1. Convert N to a string.
  2. Iterate through the characters of the string and count occurrences of the digit D.

Question 21: Toggle the case of every character of a string (5 marks)

Implement a Java program that toggles the case (converts uppercase characters to lowercase and vice versa) of every character in a given string.

Algorithm:

  1. Iterate through the string and for each character, check if it's uppercase or lowercase, and toggle its case.

Question 22: Calculate the total number of vowels and consonants in a String (10 marks)

Write a Java program to calculate the total number of vowels and consonants in a given string.

Algorithm:

  1. Initialize variables for counting vowels and consonants.
  2. Iterate through the string and classify each character as a vowel or consonant.
  3. Update the respective counters.

Question 23: Reverse an Array without using extra space (10 marks)

Create a Java program to reverse an array of integers without using extra space (i.e., do it in-place).

Algorithm:

  1. Use two pointers, one starting from the beginning and one from the end, and swap elements until they meet in the middle.

 Question 24: Input an NxN matrix and display it row-wise and column-wise (10 marks)

Write a Java program that takes an NxN matrix as input and displays its contents row-wise and column-wise.

Algorithm:

  1. Use nested loops to iterate through the matrix and print its rows and columns.

Good luck with your Java test!

 

HTML5 Test

Instructions:

  • Total Marks: [Total Marks]
  • Time Allowed: [Time Allowed]
  • Attempt all questions.
  • Write your HTML and CSS code in the space provided.
  • Ensure your code is well-structured and follows HTML5 syntax.
  • If you encounter any issues or have questions, raise your hand and wait for assistance.

Question 1: Create a Basic HTML Page (5 marks)

Write HTML and CSS code to create a basic HTML page with the following elements:

  • A title in the browser tab.
  • A heading with the text "Welcome to HTML5 Test" (use an h1 element).
  • A paragraph with the text "This is a test of your HTML5 skills."
  • Change the background color of the page to light blue (#ADD8E6).

Question 2: Create an Ordered List (5 marks)

Write HTML code to create an ordered list with at least three items. Each list item should contain a different programming language (e.g., HTML, CSS, JavaScript).


Question 3: Create a Hyperlink (5 marks)

Create an HTML hyperlink that links to the "https://www.example.com" website. The link text should say "Visit Example.com."


Question 4: Create a Table (10 marks)

Write HTML code to create a table with the following structure:

  • Three columns: Name, Age, and City.
  • At least three rows of data.
  • Use appropriate table elements (table, tr, th, td).

Question 5: Create a Form (10 marks)

Create an HTML form that includes the following elements:

  • A text input field for the user's name.
  • A radio button group with two options for gender: Male and Female.
  • A dropdown (select) for selecting a country (include at least three options).
  • A "Submit" button to submit the form.

Question 6: Add HTML5 Semantic Elements (10 marks)

Modify your HTML code from Question 1 to include HTML5 semantic elements. Use <header>, <nav>, <main>, <article>, and <footer> to structure your page.


Question 7: Create a Multimedia Element (10 marks)

Write HTML code to embed an image in your page. Use the <img> element to display an image of your choice. Make sure to include an alt attribute for accessibility.


Question 8: Create a Video Element (10 marks)

Embed a video in your HTML page using the <video> element. Include controls for play/pause and volume. Use a video source of your choice.


Question 9: Create a Canvas Element (10 marks)

Write HTML code to include a <canvas> element on your page. Use JavaScript to draw a simple shape (e.g., a rectangle or circle) on the canvas.


Question 10: Create a Local Storage Example (10 marks)

Write HTML and JavaScript code to create a simple form that allows a user to enter their name. Store this name in local storage when the form is submitted and display it on the page when the page is reloaded.


 Question 11: Create a Responsive Web Page (15 marks)

Modify your HTML code from Question 1 to create a responsive web page. Ensure that the page layout adjusts to different screen sizes. You can use CSS media queries for this purpose.


Question 12: Create a Web Page with CSS Styling (15 marks)

Enhance your HTML code from Question 1 by applying CSS styles to elements. Style the heading, paragraph, and any other elements as you see fit. Be creative with your design.


Question 13: Embed an External JavaScript File (10 marks)

Link an external JavaScript file to your HTML page. Create a simple JavaScript function that displays an alert when a button is clicked. Add the button to your HTML.


Question 14: Create a Dropdown Navigation Menu (10 marks)

Modify your HTML code from Question 6 to create a dropdown navigation menu. Use HTML and CSS to make the menu items expand when hovered over.


Question 15: Create a Web Page with Audio (10 marks)

Enhance your HTML code from Question 1 by adding an <audio> element. Include an audio source of your choice, and provide controls for play/pause and volume.


Good luck with your HTML5 test!

 



Comments

Popular posts from this blog

FrontEnd - FAQs - Part 1

Java Script - FAQs

CoreJava - ClassesObjectsMethods - Assignment