0% found this document useful (0 votes)
4 views

Assignment Questions - Java Methods

The document contains a series of assignment questions focused on Java methods, including tasks such as computing averages, counting vowels, displaying middle characters, checking leap years, and finding the smallest number among three inputs. Each question is accompanied by example inputs and expected outputs. The assignments range in difficulty from easy to medium.

Uploaded by

Shreya Mehta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment Questions - Java Methods

The document contains a series of assignment questions focused on Java methods, including tasks such as computing averages, counting vowels, displaying middle characters, checking leap years, and finding the smallest number among three inputs. Each question is accompanied by example inputs and expected outputs. The assignments range in difficulty from easy to medium.

Uploaded by

Shreya Mehta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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

You might also like