Section A
[Answer all Questions]
1. Do as directed
a) Give one
example each of a primitive data type and a composite data type.
b) Give one point
of difference between unary and binary operators.
2. Write a Java
statement to input / read the following from the user using the keyboard:
i) Character
ii) String
3. What will be
the output for the following program segment?
int a=0, b=30,
c=40;
a = --b + c++ +
b;
System.out.println("a="
+ a);
4. Write one word
answer for the following:
i) A method
that converts a string to a primitive integer data type
ii) The default
initial value of a boolean variable data type
5. Name the
primitive data type in Java that is:
(i) a 64-bit
integer and is used when you need a range of values wider than those provided
by int.
(ii) a single
16-bit Unicode character whose default value is ‘\u0000'
- Give the output
System.out.println("The King said \"Begin at the
beginning!\" to me.");
7. What are the
types of casting shown by the following examples:
(i) char c =
(char)120;
(ii) int x =
‘t’;
- Differentiate between if and switch statement
9. Give the output
of the following code segment when (i) opn = ‘b’ (ii) opn = ‘x’ (iii) opn =
‘a’.
switch(opn)
{
case 'a':
System.out.println("Platform
Independent");
break;
case 'b':
System.out.println("Object
Oriented");
case 'c':
System.out.println("Robust and
Secure");
break;
default:
System.out.println("Wrong
Input");
}
10. What is the
difference between break and continue statements when they occur in a loop.
11. What is an
infinite loop? Write an infinite loop statement.
12. Give the output
of the following program segment and also mention the number of times the loop
is executed:
int a,b;
for(a=6,b=4;a<=24;a=a+6)
{
if(a%b==0)
break;
}
System.out.println(a);
- Find and correct the errors in the following program segment:-
int n[] =
(2,4,6,8,10);
for(int i=0;
i<=5; i++)
System.out.println("n["
+ i + "] = " + n[i]);
14. Name the search
or sort algorithm that:
(i)
Makes several passes through the array, selecting the next
smallest item in the array each time and placing it where it belongs in the
array.
(ii) At each stage,
compares the sought key value with the key value of the middle element of the
array.
15. What is the
output of the following?
String S1 =
"Hi";
String S2 =
"Hi";
String S3 =
"there";
String S4 =
"HI";
System.out.println(S1
+ "equals" + S2 + "->" + S1.equals(S2));
System.out.println(S1
+ "equals" + S3 + "->" + S1 .equals(S3));
System.out.println(S1
+ "equals" + S4 + "->" + S1 .equals(S4));
System.out.println(S1
+ "equalsIgnoreCase" +S4 + "->" +
S1.equalsIgnoreCase(S4));
16. State the
values stored in variables str1 and str2
String s1 =
"good";
String
s2="world matters";
String str1 =
s2.substring(5).replace('t','n');
String str2 =
s1.concat(str1);
Section B
[Answer any four Questions]
1. Write a program
to check if a number is a Magic Number or not.
A number is
said to be a Magic number if the sum of its digits are calculated till a single
digit is obtained by recursively adding the sum of its digits. If the single
digit comes to be 1 then the number is a magic number. Example- 199 is a magic
number as 1+9+9=19 but 19 is not a single digit number so 1+9=10 and then 1+0=1
which is a single digit number and also 1. Hence it is a magic number.
2. Write a menu driven to accept a number from the user and check whether
it is a Palindrome or a Perfect number.
1. Palindrome number – (a number is a Palindrome which when read in
reserve order is same as read in the right order)
Example: 11, 101, 151, etc.
Example: 11, 101, 151, etc.
2. Perfect number – (a number is called Perfect if it is equal to the sum
of its factors others than the number itself.)
Example: 6 = 1 + 2 + 3
Example: 6 = 1 + 2 + 3
3. Write a program to accept the names of 10 cities in a single dimension
string array and their STD (Subscribers Trunk Dialing) codes in another single
dimension integer array. Search for a name of a city input by the user 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.
Use Binary Search Technique for sorting
4.
Write a menu driven program in Java:
(a) to input a number and check whether it is a NEON number or not
(b) to print the REPUNIT series: 1, 11, 111, 1111, .... upto 'n' terms
Note:
NEON:
A number is said to be NEON, if sum of all the digits of the square of
the number is equal to the number itself.
For example 9 is a NEON number
(Workings: Square of 9 = 81. Sum of digits of square: 8 + 1 = 9)
5.
Define a class and store the given
city names in a single dimensional array. Sort these names in alphabetical
order using the Bubble Sort technique only.
INPUT : Delhi, Bangalore, Agra, Mumbai, Calcutta
OUTPUT : Agra, Bangalore, Calcutta, Delhi, Mumbai
6. Write the
following two programs separately
i. Write a
program that encodes a word in Piglatin. To translate word into Piglatin word,
convert the word into uppercase and then place the first vowel of the original
word as the start of the new word along with the remaining alphabets. The
alphabets present before the vowel being shifted towards the end followed by “AY”.
Sample
Input(1): London Sample Output(1): ONDONLAY
Sample
Input(2): Olympics Sample Output(2): OLYMPICSAY
ii. Write a
program to assign a full path and file name as given below. Using library
functions,extract and output the file path, file name and file extension
separately as shown.
Input
C:\Users\adm in\Pictures\flower.jpg
Output Path:
C:\Users\admin\Pictures\
File name:
flower
Extension: jpg
SOLVE THE QUESTIONS AND SUBMIT BY 25/06/2018
No comments:
Post a Comment