Java Methods
Assignment Questions
Assignment Questions
Q1 - Write a Java method to compute the average of three numbers (Easy)
Input1:
25
45
65
Output1:
45
Input2:
25
25
25
Output2:
25
Q2 - Write a Java method to count all vowels in a string (Medium)
Input1: (consists of all lowercase letters)
coding
Output1:
Input2: (consists of all lowercase letters)
heaps
Output2:
Q3 - Write a Java method to display the middle character of a string.(Easy)
(Easy)
Note: a) If the length of the string is even there will be two middle characters.
b) If the length of the string is odd there will be one middle character.
Input1:
350
Output1:
Input2:
4004
Output2:
00
Cracking the Coding Interview in JAVA - Foundation
Assignment Questions
Q4 - Write a Java method to check whether a year (integer) entered by the user is a leap year
(Easy)
or not.
Input1:
2017
Output1:
False
Input2:
2022
Output2:
False
Q4 - Write a Java method to find the smallest number among three numbers. (Medium)
Input1:
25
37
29
Output1:
25
Input2:
25
25
25
Output2:
25
Cracking the Coding Interview in JAVA - Foundation