11) Write a Java program to input a number from the user and check and display whether it is a ‘Prime number’ or not.
12) Write a program to accept a number and check whether it is a ‘Spy Number’ or not. (A number is a spy if the sum of its digits equals the product of its digits.)
Sample Input: 1124
Sum of the digits=1+1+2+4=8
Product of the digits = 1*1*2*4 = 8
13) A Special two-digit number is such that
when the sum of its digits is added to the product of its digits, the result is
equal to the original two-digit number.
Example: Consider the number 59.
Sum of digits=5+9=14
Product
of digits=59 450
Sum of the sum of digits and product of digits
14+45=59
Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If the value is equal to the number input, then display the message "Special 2-digit number" otherwise, display the message "Not a special two-digit number".
14) Write the program in Java to display the first ten terms of the following series:
1, 2, 4, 7, 11,.
15)Write a program to input a set of 20 letters using a for
loop. Convert each letter into upper case. Find and display the number of
vowels and number of consonants present in the set of given letters. (Note: Do
not use array)
16) Design a class to overload a function area( )
as follows:
double area (double a, double b, double c)
with three double arguments, returns the area of a scalene triangle using the formula: area = where s = (a+b+c) / 2
double area (int a, int b, int height)
with three integer arguments, returns the area of a trapezium using the formula:
area = (1/2) height (a + b)
double area (double diagonal1, double diagonal2) with two double arguments, returns the area of a rhombus using the formula:
area =
1/2(diagonal1 x diagonal2)
17) Design a class RailwayTicket with following description:
Instance variables/data members:
String name — To store the name of the customer
String coach — To store the type of coach customer wants to travel
long mobno — To store customer’s mobile number
int amt — To store basic amount of ticket
int totalamt — To store the amount to be paid after updating the original amount
Member methods:
void accept() — To take input for name, coach, mobile number and amount.
void update() — To update the amount as per the coach selected
(extra amount to be added in the amount as follows)
Type of Coaches | Amount |
---|---|
First_AC | 700 |
Second_AC | 500 |
Third_AC | 250 |
Sleeper | None |
void display() — To display all details of a customer such as name, coach, total amount and mobile number.
Write a main method to create an object of the class and call the above member methods.
18) Write a program to input and sort the weight of ten
people. Sort and display them in ascending order using the Bubble sort
technique.
19)Write a program to accept the names of 10 cities in a single-dimensional
string array and their STD (Subscribers Trunk Dialling) codes in another single-dimensional integer array. Search for the name of a city input by the user using Linear
search in the list. If found, display "Search Successful" and
print the name of the city along with its STD code, or else display the message
"Search unsuccessful, no such city in the list".
20)Write a program to perform a Binary search
on a list of integers given below, to search for an element input by the user. If it is found display the element along with its position, otherwise display
the message "Search element not found".
No comments:
Post a Comment