Professional Documents
Culture Documents
Questions
Questions
(see hint#1)
3. WAF printASCII() that takes a character as an argument and prints it's ASCII value.
4. WAF getSum() that takes and array of integers and returns their sum.
5. WAF getAvg() that takes and array of integers and returns their average.
6. WAF getMax() that takes and array of integers and returns their maximum.
7. WAF getMin() that takes and array of integers and returns their minimum.
8. Write functions getLCM() and getHCF() to find the LCM and HCF of two numbers.
8. WAF ifPalindrom() that takes an integer and returns true if the number is palindrome.
8. WAF getSumOfDigits() that takes an integer and returns the sum of the digits of the number(e.g., if
number is 2057 then it will return 2+0+5+7=14)
11. WAP using switch to calculate the area of a circle, a rectangle or a triangle depending upon user's
choice. It should ask whether to continue or not and perform accordingly.
12. WAF printStar() that takes an integer 'n' and prints n rows of stars in the following manner. if n=5
then it should print:
**
***
****
*****
13. WAF printNumberPattern() that takes an integer 'n' and prints n rows in the following manner. if n=5
then it should print:
45
345
2345
12345
14. WAP that asks the user to enter number of names and then ask to enter names. Then it should print
all names with number of vowels. (e.g. if user enters 5 then it will ask the user to enter names 5 times.
Let's say user enters the following names 'Vishal', 'aman', 'omega','chetan','naman' then it should print
'Vishal : 2', 'aman : 1', 'omega : 3','chetan : 2','naman : 1')
15. WAF getFactorial() that takes a non negative integer and returns it's factorial.
14. WAF howMany() that takes two arguments an array of double and a double value and returns the
number how many time the value exists in the array. (e.g., if array is {1.2,0,3.5,1.2} and value is 1.2 then
it should return 2)
16. Write a program to input n numbers into an integer array and to reverse the set of numbers without
using functions
18. WAF cosine() that takes two arguments 'x' as double and 'n' as integer to compute cosine series i.e.,
cos(x): 1-(x^2/2!)+(x^4/4!)-(x^6/6!)+...(x^2n/2n!)
19. WAF that takes an array of integers and updates the array by swapping the highest element with the
first element.(e.g., if array={2,1,5,0} the the function should update the array to {5,1,2,0})
20. WAF addMatrices() that takes two square matrices and returns the sum of them.
21. WAF addDiagonal() that takes a square matrix and returns the sum of it’s all diagonal
elements.(Note: Diagonal elements are m[0][0],m[1][1],m[2][2],…)
21. WAF to check if a year is leap or not using ternary operator ‘?:’.
6. Fill the following to establish the relationship between primitive data type(implicit typecasting
diagram):
Chapter 02
1. What is the output of the following line of codes:
System.out.println(a);
System.out.println(10/0.0);
System.out.println(0/0.0);
System.out.println(“2”>”1”);
System.out.println(5|5);
Object o=new String("my object");
System.out.println(o instanceof String);
System.out.println(o instanceof Object);
2. When ArithmeticException occurs?
3. What is the difference b/w == and .equals()?
4. Explain implicit and explicit typecasting with example.