Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

1. WAF cube() that takes a double value and returns it's cube.

(see hint#1)

2. WAF comparison() that takes two double values and returns

+1 if first argument is greater than second argument

-1 if second argument is greater than first argument

0 if both are equal

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)

9. WAF isPrime() to check if a number is prime or not.

10. WAF to find all prime numbers up to given number

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

17. WAF that computes the following series:

1 + 1/1! + 1/2! + 1/3! + ... +1/n!(see hint#2)

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!)

Where x is angle and n is number of terms

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. Create a 3-D array a of integers with the following structure:


And initialize each element as a[i][j][k]=(i+1)*(j+1)*(k+1) .e.g., a[1][0][1]=2*1*2=4. Print them too.

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 ‘?:’.

1. Write all eight data types.


2. What is the output of the following snippet of code:
int x=10;
int y=010;
int z=0x10;
System.out.println(x+"----"+y+"----"+z);
3. Which of the following lines are invalid and why:
int x=10;
long l=10L;
long l=10;
int x=10L;
byte b=130;
short s=32768;
float f=123.456;
float f=123.456f;
double d=123.456;
double f=123.456f;
double d=0x123.456;
double d=0123.456;
double d=0xBeef;
double d=0xchiken;
char ch=100;
char ch=0xBeef;
char ch=0xBeefBeef;

4. Give the memory representation of the following array:


int[][][] a=new int[2][][];
a[0]=new int[3][];
a[0][0]=new int[1];
a[0][1]=new int[2];
a[0][2]=new int[3];
a[1]=new int[2][2];
5. What is the output of the following snippet of code:

int[] x=new int[3];


System.out.println(x.length()+”…”+x[0]);

6. Fill the following to establish the relationship between primitive data type(implicit typecasting
diagram):

7. Explain the below two statements:


1. Every variable in java should be either instance or static or local.
2. Every variable in java should be either primitive or reference

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.

1. Give the output of the following code:


while(true){
continue;
System.out.println("asdf");
}
2. Give the output of the following code:
String name="Tanme";
switch(name){
case "Waquar":System.out.println("Hi! I am Waquar");
case "Tanme":System.out.println("Hi! I am Tanme");
default:System.out.println("Hi! I am Default");
}
3. WAP to display each element of
int [][] x={{1,2,3},{10,20,30,40}};
using FOR EACH LOOP
4.

You might also like