Back to Dsa Bootcamp Java

Video Link

assignments/04-functions.md

latest3.0 KB
Original Source

Video Link

  1. Define two methods to print the maximum and the minimum number respectively among three numbers entered by the user.

  2. Define a program to find out whether a given number is even or odd.

  3. A person is eligible to vote if his/her age is greater than or equal to 18. Define a method to find out if he/she is eligible to vote.

  4. Write a program to print the sum of two numbers entered by user by defining your own method.

  5. Define a method that returns the product of two numbers entered by user.

  6. Write a program to print the circumference and area of a circle of radius entered by user by defining your own method.

  7. Define a method to find out if a number is prime or not.

  8. Write a program that will ask the user to enter his/her marks (out of 100). Define a method that will display grades according to the marks entered as below:

<pre> Marks Grade 91-100 AA 81-90 AB 71-80 BB 61-70 BC 51-60 CD 41-50 DD <=40 Fail </pre>
  1. Write a program to print the factorial of a number by defining a method named 'Factorial'. Factorial of any number n is represented by n! and is equal to 1 * 2 * 3 * .... * (n-1) *n. E.g.-
<pre> 4! = 1 * 2 * 3 * 4 = 24 3! = 3 * 2 * 1 = 6 2! = 2 * 1 = 2 Also, 1! = 1 0! = 1 </pre>
  1. Write a function to find if a number is a palindrome or not. Take number as parameter.

  2. Convert the programs in flow of program, first java, conditionals & loops assignments into functions.

  3. Write a function to check if a given triplet is a Pythagorean triplet or not. (A Pythagorean triplet is when the sum of the square of two numbers is equal to the square of the third number).

  4. Write a function that returns all prime numbers between two given numbers.

  5. Write a function that returns the sum of first n natural numbers.