Skip to content

davinash97/Programming-Questions-Java

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Programming Questions

Easy - Intermediate Programming Questions taken from ChatGPT

Questions:

  1. Write a function that takes an array of numbers as input and returns a new array with all the even numbers from the input array.

  2. Write a function that takes a string as input and returns the same string with all the vowels removed.

  3. Write a function that takes two arrays of numbers as input and returns a new array that contains only the elements that are present in both arrays. For example, if the two input arrays are [1, 2, 3, 4] and [3, 4, 5, 6], the function should return [3, 4].

  4. Write a function that takes an array of strings as input and returns the longest string in the array. If there are multiple strings with the same maximum length, return the first one. For example, if the input array is ["dog", "cat", "bird", "elephant"], the function should return "elephant".

  5. Write a function that takes a string as input and returns the reverse of the string. For example, if the input string is "hello", the function should return "olleh".

  6. Write a function that takes an array of numbers as input and returns the sum of all the positive numbers in the array. For example, if the input array is [-1, 3, 5, -2, 8], the function should return 16 (3 + 5 + 8).

  7. Write a function that takes an array of numbers as input and returns a new array that contains only the numbers that are greater than zero and even. For example, if the input array is [1, 2, -3, 4, 0, 7, 8], the function should return [2, 4, 8].

  8. Write a function that takes two parameters, a string and a letter, and returns the number of times the letter appears in the string (case-insensitive). For example, if the input string is "Hello, World" and the letter is "o", the function should return 2.

  9. Write a function that takes an array of numbers as input and returns the second largest number in the array. For example, if the input array is [3, 5, 1, 4, 6, 2], the function should return 5.

  10. Write a function that finds the largest value from a given array without sorting the array.

  11. Write a function called sumDigits that takes an integer as input and returns the sum of its digits. For example, sumDigits(123) should return 6 (since 1 + 2 + 3 = 6).

  12. Write a function that takes a string as input and returns true if the string is a palindrome (i.e. if it reads the same backward as forward), and false otherwise. Ignore spaces, punctuation, and capitalization when determining whether the string is a palindrome. For example, "A man, a plan, a canal: Panama" is a palindrome.

  13. Write a function that takes an array of integers as input and returns the largest difference between any two elements in the array. For example, if the input array is [1, 2, 4, 7], the function should return 6 (the difference between 1 and 7).

  14. Write a function that takes a string as input and returns a new string that contains only the first occurrence of each character in the input string, in the order in which they appear. For example, if the input string is "banana", the function should return "ban".

  15. Write a function that takes a number as input and returns "Fizz" if the number is divisible by 3, "Buzz" if the number is divisible by 5, and "FizzBuzz" if the number is divisible by both 3 and 5. If the number is not divisible by either 3 or 5, the function should return the input number. For example, if the input number is 15, the function should return "FizzBuzz".

  16. Write a function that takes an array of numbers and returns the sum of all the even numbers in the array.

  17. Write a program that generates a random number between 1 and 100, and asks the user to guess the number. The program should give the user hints (e.g. "higher" or "lower") until they guess the correct number.

  18. Write a function that takes a string as input and returns the number of vowels in the string. For the purposes of this problem, consider the vowels to be "a", "e", "i", "o", and "u", regardless of case. For example, if the input string is "Hello, World!", the function should return 3.

  19. Write a function that takes an array of objects as input, where each object represents a book with a title and an author. The function should return an array of authors, where each author appears only once in the array, in alphabetical order. For example, if the input array is [{title: "To Kill a Mockingbird", author: "Harper Lee"}, {title: "1984", author: "George Orwell"}, {title: "Pride and Prejudice", author: "Jane Austen"}, {title: "To Kill a Mockingbird", author: "Harper Lee"}], the function should return ["George Orwell", "Harper Lee", "Jane Austen"].

  20. Write a program that finds the first non-repeating character in a string and returns it. For example, given the string "hello", the program should return "h". If there are no non-repeating characters, the program should return null.

About

Questions are taken from ChatGPT

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%