Defining Methods

The method declaration takes the following form:

<modifiers> <return_type> <name> (
[throws <exception>] {
< block >


public int addDays(int days) {
< block > // Method code here

Example Programs

Program [1]

A Circular Prime is a prime number that remains prime under cyclic shifts of its digits. When the leftmost digit is removed and replaced at the end of the remaining string of digits, the generated number is still prime. The process is repeated until the original number is reached again.

A number is said to be prime if it has only two factors I and itself.

Write a program to accept one no check the number where it is Circular Prime or Not.

Example 1

INPUT :N = 197


Example 2

INPUT :N = 1193

OUTPUT: 1193 1931 9311 3119 1193 IS A CIRCULAR PRIME

Example 3

INPUT :N = 29


View Solution

Program [2]

Write a Program in Java to input a number and check whether it is a Bouncy Number or not.

Increasing Number : Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 22344.

Decreasing Number : Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, 774410.

Bouncy Number : We shall call a positive integer that is neither increasing nor decreasing a “bouncy” number; for example, 155349. Clearly there cannot be any bouncy numbers below 100.


Enter a number : 22344

The number 22344 is Increasing and Not Bouncy

Enter a number : 774410

The number 774410 is Decreasing and Not Bouncy

Enter a number : 155349

The number 155349 is bouncy

View Solution

Program [3]

Design a program to accept a fifteen digit number from the user and check whether it is a valid IMEI number or not. For an invalid input, display an appropriate message.

The International Mobile Station Equipment Identity or IMEI is a number, usually unique, to identify mobile phones, as well as some satellite phones. It is usually found printed inside the battery compartment of the phone.

The IMEI number is used by a GSM network to identify valid devices and therefore can be used for stopping a stolen phone from accessing that network.

The IMEI (15 decimal digits: 14 digits plus a check digit) includes information on the origin, model, and serial number of the device.

The IMEI is validated in three steps:

1. Starting from the right, double every other digit (e.g., 7 becomes 14).

2. Sum the digits (e.g., 14 → 1 + 4).

3. Check if the sum is divisible by 10.

Sample output

1. Enter a 15 digit IMEI code : 654122487458946 Output : Sum = 80 Valid IMEI Code

2. Enter a 15 digit IMEI code : 799273987135461 Output : Sum = 79 Invalid IMEI Code

3. Enter a 15 digit IMEI code : 79927398713 Output : Invalid Input

View Solution

Program [4]

A positive natural number , (for example 27) can be represented as follows:




where every row represents a combination of consecutive natural numbers, which add up to 27.

Write a program which inputs a positive natural number N and prints the posibale consecutive  number combinations, which when added given N.

Test your program for the following data and some random data.

View Solution

Program [5]

A Class quad contains the following data members and member function s to find the roots of quadratic equation.

Class Name : quad

Data Members:

a,b,c(float) x,y(float)

Member Function/Method:

quad(float,float,float): constructor to assign values to the data members

float discriminant(): to return the discriminant [b1-4ac]

void root_equal(): to display the root if both roots are equal.

void image(): to display the root if roots are imaginary.

void root_real(): to display the two real, unequal roots.

void root(): to call other appropriate functions to find the solutions of the problem.

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