-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQuestions.txt
406 lines (281 loc) · 13.5 KB
/
Questions.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
----------------------------------------------
******* Java Assignment Section-1 *********
---------------------------------------------
1. Get yourself acquainted with java environment. Find out "javac" & "java" in your JDK box.
2. Understand the system variable : PATH
3. Write a Java program to print 'Hello' on screen and then print your name on a separate line.
4. Write a Java program to print 'Hello' on screen and then print your name on the same line.
5. Write a program to take "name" as command line argument and print "Hello "+<name> on the console?
>> java MyFirstJavaProgram Shakir
Hello Shakir
6. Write a java program to take three numbers from command line and print the average ?
>> java Avg 5 6 4
Average=5
7. Write a java program to calculate simple interest, get the required inputs from command line ?
Hint : SimpleInterest = (principal * rate * years)/100.0
8. Write a java program to convert temperature from celsius to fahrenheit, get input from command line ?
Hint : F = (9*C/5) + 32
9. Write a java program to print following face(pattern) on screen -
+"""""+
[| o o |]
| ^ |
| '-' |
+-----+
10. Write a Java program to print the sum (addition), multiply, subtract, divide and remainder of two numbers received from command line?
// double x = Double.parseDouble(args[0]);
----------------------------------------------
******* Java Assignment Section-2 ********* Prev=+8
---------------------------------------------
1. Write a program to take "name" from user using Scanner and greet as shown below-
>> Enter your name : Shakir
Hello Shakir , Welcome to Java World.
2. Write a java program to take 5 numbers using Scanner and print the average ?
>> Enter 5 numbers : 1 2 3 4 5
Average = 3
>> Enter 5 numbers : 2 3 5 7 9
Average = 5.2
3. Write a java program to calculate simple interest, get the required inputs
from Scanner ?
Hint : SI = (principal * rate * years)/100
4. Write a program to calculate the monthly in hand salary of an employee :
take input for basic salary,
HRA is 40% of basic salary,
PF amount to be deducted is 12% of basic,
Medical allowance is Rs 1200 per month,
Traveling allowance is Rs 800 per month,
Professional tax to be deducted is Rs 300.
5. Write a Java program to print the area and perimeter of a rectangle. Take required input using Scanner?
Hint :
Area = width * height
Perimeter = 2 * ( width + height)
6. Write a Java program to print the area and perimeter of a circle. Take required input using Scanner?
Hint :
Area = Math.PI * radius * radius
Perimeter = 2* Math.PI* radius
7. Write a java program to calculate compound interest, get the required inputs
using Scanner ?
8. Write a java program to read roll no, name and marks of three subjects and calculate the total and percentage.
Test Data :
Input the Roll Number of the student :784
Input the Name of the Student :James
Input the marks of Physics, Chemistry and Computer Application : 70 80 90
Expected Output :
Roll No : 784
Name of Student : James
Marks in Physics : 70
Marks in Chemistry : 80
Marks in Computer Application : 90
Total Marks = 240
Percentage = 80.00
----------------------------------------------
******* Java Assignment Section-3 ********* Prev=+16
---------------------------------------------
1. Write a java program to swap two numbers stored in local variables?
2. Write a java program to swap two numbers stored in local variables without using additional variable?
3. Write a java program to accept two integers and check whether they are equal or not?
>> Enter two integers : 15 15
first and second number are equal.
4. Write a java program to check whether a given number is positive or negative?
5. Write a java program to check whether a given number is even or odd?
6. Write a java program to read age of a person, check if he/she is eligible to cast vote or not?
7. Write a java program to read a number entered by user. Print -1 if this number is negative, 1 if it is positive, 0 if it is neither positive nor negative?
8. Write a program to find the largest of two numbers?
9. Write a program to find the largest of three numbers?
10. Write a program to find the smallest of five numbers?
11. Write a java program to read roll no, name and marks of three subjects and calculate the total, percentage and division.
Test Data :
Input the Roll Number of the student :784
Input the Name of the Student :James
Input the marks of Physics, Chemistry and Computer Application : 70 80 90
Expected Output :
Roll No : 784
Name of Student : James
Marks in Physics : 70
Marks in Chemistry : 80
Marks in Computer Application : 90
Total Marks = 240
Percentage = 80.00
Division = First
12. Write a java program to read temperature in centigrade and display a suitable message according to temperature state below :
Temp < 0 then Freezing weather
Temp 0-10 then Very Cold weather
Temp 10-20 then Cold weather
Temp 20-30 then Normal in Temp
Temp 30-40 then Its Hot
Temp >=40 then Its Very Hot
Test Data :
42
Expected Output :
Its very hot.
13. Write a Java program to print the ascii value of a given character?
14. Write a Java program that takes a year from user and print whether that year is a leap year or not.
Hint : a leap year is divisible by 4 and (not div by 100 or if div by both 100 &400)
15. Write a java program to check if a given number is divisble by 3 and 5 ?
16. Write a java program to ask user to enter test marks of three subjects such as Phy, Chem, Math. Max marks for each subject is 100. Now calculate average of marks. Display following message based on average marks calculated -
avg < 30 : You are failed.
avg >= 30 but < 60 : You passed with Second division
avg >=60 but < 80 : You passed wirh Fiear division
avg>=80 : You passed with First class distinction
17. Write a java program to ask user to enter a number between 1 and 7, print week day as per below mappings -
(1 - Monday, 2-Tuesday, .... 7-Sunday)
18. Write a Java program to check if character entered by user is a vowel, consonant or other character?
19. Write a java program to ask user to enter month number (1-12) , print month name as per below mappings -
(1 - January, 2-Feburary ... 12- December)
20. Write a program to read 5 numbers from user, print the second highest number?
----------------------------------------------
******* Java Assignment Section-4 ********* +36
---------------------------------------------
1. Write a java program to print first 10 natural numbers and their sum?
2. Write a java program to read 10 numbers from keyboard and find their sum and average?
3. Write a program in java to display the multiplication table of a given integer?
>> Enter the number : 5
5 X 1 = 5
5 X 2 = 10
.
.
5 X 10 = 50
4. Write a program to calculate the factorial of the given number?
5. Write a program to display the pattern like right angle triangle using an asterisk as shown below:
*
**
***
****
6. Write a program to display the pattern like right angle triangle with a number as shown below :
1
12
123
1234
7. Write a program to make such a pattern like right angle triangle with a number which will repeat a number in a row, as shown below :
1
22
333
4444
8. Write a program to make such a pattern like right angle triangle with number increased by 1 as shown below :
1
2 3
4 5 6
7 8 9 10
9. Write a program to make such a pattern like a pyramid with an asterisk, as show below :
*
* *
* * *
* * * *
10. Write a program to make such a pattern like a pyramid with a number which will repeat the number in the same row as shown below :
1
2 2
3 3 3
4 4 4 4
11. Write a program to check whether a given number is a perfect number or not?
Note :
Defintion of Perfect Number : sum of all divisor of the number is equal to the number itself.
eg. Number = 6 is perfrect because
All positive divisor = 1 2 3, their sum=6
12. Write a program to check whether a given number is an armstrong number or not?
Note : When the sum of the cube of the individual digits of a number is equal to that number, the number is called Armstrong number. For Example 153 is an Armstrong number because 153 = 1^3 +5^3 + 3^3.
13. Write a program to determine whether a given number is prime or not?
14. Write a program to display the first n terms of Fibonacci series.
Fibonacci series 0 1 2 3 5 8 13 .....
Test Data :
Input number of terms to display : 10
Expected Output :
Here is the Fibonacci series upto to 10 terms :
0 1 1 2 3 5 8 13 21 34
15. Write a program to display the number in reverse order.
16. Write a program to check whether a number is a palindrome or not.
Note: If reverse of a number is same as that of number , then it is called palindrome. eg. 11, 151, 121,
17. Write a program to check whether a given number is a Strong Number or not?
Note : If sum of factorial of each digit of a number is equal to that number, then that number is called strong number.
18. Write a program to find the length of a string without using the library function?
19. Write a program to print all numbers between 1 & 100 which are divisible by 3 and 5 both?
----------------------------------------------
******* Java Assignment Section-5 ********* Prev = 36+19=55
---------------------------------------------
1. Create a class Emp with fields like empId, name,dept,salary,address.
Write required constructors for initialization
Write a method displayEmpDetails() in the same class.
Write another test class , where you have to take emp details from user using Scanner and create object and call methods.
2. Create a class Circle, it will have only one constructor which accepts radius as an argument. Write two methods in the class - calcuateArea(), calculatePermiter().
Write test class to test method calls.
class Circle{
int rad;
Circle(int r){this.rad = r;}
double calArea(){}
double calPerimeter(){}
}
----------------------------------------------
******* Java Assignment Section-6 ********* Prev=57
---------------------------------------------
1. Install Eclipse with help of lab faculty, write and run some java programs.
Set it up for java 8.
2. Practice whatever is tought in the classroom - final, access modifier, constructors
3. Write a menu driven billing system for a Snacks center, items available are Tea(Rs. 10), Samosa (Rs. 20), Sandwitch(Rs. 50), Green Tea (Rs. 15) etc. as follows -
****Welcome to Snack Center *********
1. Tea (Rs. 10)
2. Green Tea (Rs. 15)
3. Samosa (Rs. 20)
4. Sandwitch (Rs. 50)
5. Generate Bill & Exit
Enter your choice : 1
Enter quantity : 2
1. Tea (Rs. 10)
2. Green Tea (Rs. 15)
3. Samosa (Rs. 20)
4. Sandwitch (Rs. 50)
5. Generate Bill & Exit
Enter your choice : 3
Enter quantity : 3
1. Tea (Rs. 10)
2. Green Tea (Rs. 15)
3. Samosa (Rs. 20)
4. Sandwitch (Rs. 50)
5. Generate Bill & Exit
Enter your choice : 5
*****BILL****
Tea 2 20
Samosa 3 60
------------
Total = 80
----------------------------------------------
******* Java Assignment Section-7 ********* Prev 58
---------------------------------------------
1. Write a java class named as NumUtil with following static methods to -
double getPower(double x, int n)
long getFactorial(int num);
boolean isPrime(int num);
boolean isEven(int num);
boolean isOdd(int num);
1.1) Write test class named as NumUtilMain to test all these methods.
1.2) Extends question 2.1 to make it menu driven, based on the user choice , read relevant data from user and call static methods.
----------------------------------------------
******* Java Assignment Section-8 ********* Prev 59
---------------------------------------------
1. Write a program to calculate average of numbers stored in an array?
2. Write a program to reverse an array of elements?
3. Write a program to find out highest and second highest number in an array?
4. Write a Java program to copy an array to another by iterating the array?
5. Write a program to concatenate two arrays (merge two array to new one)?
a[] = {1,2,3}
b[] = {4,5}
c[] = {1,2,3,4,5}
6. Write a Java program to test if an array contains a specific value?
7. Write a Java program to find the index of an array element?
8. Write a Java program to find the duplicate values of an array of integer values?
9. Write a Java program to find the common elements between two arrays of integers?
10. Write a program to add two matrix of numbers?
11. Write a program to Sort an array in ascending order? [Notes : Arrays.sort()]
12. Write a program to Sort strings in alphabetical order?
----------------------------------------------
******* Java Assignment Section-9 ********* Prev 59+12=71
---------------------------------------------
1. Write a java program to print first 10 natural number using recursion?
2. Write a java program to calculate the sum of numbers from 1 to N using recursion?
3. Write a program to calculate the product of two integers using recursion? (Multiplication & Division operators are not allowed)
4. Write a program to calculate the power of any number using recursion?
5. Write a recursive program to print Fibonacci Series for given number of terms?
Input number of terms for the Series (< 20) : 10
The Series are :
1 1 2 3 5 8 13 21 34 55
6. Write a program to find the sum of digits of a number using recursion?
7. Write a program to find the Factorial of a number using recursion?
8. Write a program to get the largest element of an array using recursion?
Total : 71+8 = 79