Types of Methods

Types of Methods


Function can be broadly classified into two categories:

Built-in function or library functions

These are inbuilt function, which are grouped together and stored in a standard java library. You can make use of these functions to get a predefined output, instead of writing your own code.

User defined Function : 

These function are designed by the user to carry out some specific tasks. These name of the method is given by the user according to his/her requirement; hence, it is called a user defined function. 


Java : Types of Methods Program List




Program [1]

Design a program to accept a day number (between 1 and 366), year (in 4 digits) from the user to generate and display the corresponding date. Also, accept ‘N’ (1 <= N <= 100) from the user to compute and display the future date corresponding to ‘N’ days after the generated date. Display an error message if the value of the day number, year and N are not within the limit or not according to the condition specified.


Test your program with the following data and some random data:

Example 1


INPUT:

DAY NUMBER: 255

YEAR: 2018

DATE AFTER (N DAYS): 22


OUTPUT:

DATE: 12 TH SEPTEMBER, 2018

DATE AFTER 22 DAYS: 4 TH OCTOBER, 2018


Example 2


INPUT:

DAY NUMBER: 360

YEAR: 2018

DATE AFTER (N DAYS): 45


OUTPUT:

DATE: 26 TH DECEMBER, 2018

DATE AFTER 45 DAYS: 9 TH FEBRUARY, 2019


Example 3


INPUT:

DAY NUMBER: 500

YEAR: 2018

DATE AFTER (N DAYS): 33


OUTPUT:

DAY NUMBER OUT OF RANGE.


Example 4


INPUT:

DAY NUMBER: 150

YEAR: 2018

DATE AFTER (N DAYS): 330


OUTPUT:

DATE AFTER (N DAYS) OUT OF RANGE.


View Solution


Program [2]

A Goldbach number is a positive even integer that can be expressed as the sum of two odd primes. Note: All even integer numbers greater than 4 are Goldbach numbers. Example: 6 = 3 + 3, 10 = 3 + 7, 10 = 5 + 5 Hence, 6 has one odd prime pair 3 and 3. Similarly, 10 has two odd prime pairs, i.e. 3 and 7, 5 and 5.

Write a program to accept an even integer ‘N’ where N > 9 and N < 50. Find all the odd prime pairs whose sum is equal to the number ‘N’.

Test your program with the following data and some random data:

Example 1: INPUT: N = 14

OUTPUT: PRIME PAIRS ARE: 3, 11 7, 7

Example 2: INPUT: N = 30

OUTPUT: PRIME PAIRS ARE: 7, 23 11, 19 13, 17

Example 3: INPUT: N = 17

OUTPUT: INVALID INPUT. NUMBER IS ODD.

Example 4: INPUT: N = 126

OUTPUT: INVALID INPUT. NUMBER OUT OF RANGE.


View Solution


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad