Defining Methods

The method declaration takes the following form:

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

Example:

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

Java : Defining Methods Program List




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

OUTPUT: 197 971 719 197 IS A CIRCULAR PRIME

Example 2

INPUT :N = 1193

OUTPUT: 1193 1931 9311 3119 1193 IS A CIRCULAR PRIME

Example 3

INPUT :N = 29

OUTPUT: 29 92 29 IS NOT A CIRCULAR PRIME


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.

Sample:

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