Practice Worksheet 4
Practice Worksheet 4
b. The ________ keyword indicates that the function is not returning any value.
a. return
b. final
c. continue
d. void
e. A function returns True or False. The return type of the function is _______.
a. void
b. String
c. boolean
d. int
g. Function add() can be used only in the same class and takes 2 integer parameters and sends back the sum of the
numbers.
Which of the following is a correct prototype for function add().
update(n , S , S1);
System.out.print(n);
System.out.print(S);
System.out.print(S1.rollno);
System.out.print(S1.name);
}
a. 1. arguments
2. actual parameters
3. formal parameters
b. 1. friendly
2. package
3. private
c. 1. void
2. return
3. continue
4. break
Q4. Choose the statement/keyword which defines the term below from the code below :
class demo
{
public static void test(double d,int i)
{
double ans = d+i;
System.out.println(ans);
SHAILESH MANJREKAR – 98194 98104
}
public static void main()
{
test(5.5 , 5);
}
}
a.prototype
1. public static void test(double d,int i)
2. public static void main()
3. both 1,2
b.arguments
1. 5.5 , 5
2. ans
3. d , i
c.signature
1. public static void test()
2. (double d,int i)
3. test(5.5 , 5)
d.formal parameters
1. 5.5 , 5
2. ans
3. d , i
e.local variables
1. 5.5 , 5
2. ans
3. d , i
rev = ________2________;
}
____3________;
}
public static _______4____________
{
if(Character.isUppercase(ch))
{
ans = ________5________;
}
else
{
ans = _________6________;
}
return ans;
}
// main program
class callBy
{
public static void main()
{
//setting initial values to various datatypes
int i =10;
String s="max";
boolean b=false;
box x=new box();
// passing to functions
changeValues(i , s , b , x );
// printing values
System.out.println(i);
System.out.println(s);
System.out.println(b);
System.out.println(x.size);
}
b. Function encrypt() takes a string and a number and returns a string, this function can be used only in the same
class. It can be called with the class name.
4. With UDT given below, Complete the code to indicate pure and impure functions
class Student
{
int rollno;
String name;
}
_______________________ ; _______________________ ;
} }
5. In the code given below, Identify Actual parameters, Formal parameters, Prototype, Signature, Return type. Define
each of them.
class coffee{
public static void main()
{
int N =10;
String S = compare( N,100);
System.out.println(S);
return “White”;
else
return “Red”;
}
}
Write a function LuckyTen() which takes an int parameter and returns boolean value (true) if the sum of the digits
is 10 and (false) otherwise. Using the function print all LuckyTen numbers between 1 and 1000.
SHAILESH MANJREKAR – 98194 98104
class lucky
{
public static void main()
{
int i;
for(i=1 ; i<=____1___ ; i++)
{
boolean x = ____2_____ ;
if( ___3_____ )
System.out.println(i);
}
}
public static ___4___ luck( ____5____ )
{
int r,s=0;
while( ___6___ )
{
r= ____7____ ;
n=n/10;
s=___8___;
}
if( ____9_____ )
return true;
else
______10______;
}
}
class printseries
{
public ___1__ void main()
{
printseries(10);
____2_____ (5,15);
}
public static void ___3__ ( ___4___ )
{
int i;
for(i=1 ; ___5__ ; i++)
{
________6______ ;
}
}
public static ___7____ ___8____(int n1 , int n2)
{
int i;
SHAILESH MANJREKAR – 98194 98104
for( _____9_______ )
{
_______10__________ ;
}
}
}