Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

JAVA Functions Based Programs Frank Function

From Frank Publication

Uploaded by

vickroid007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
14 views

JAVA Functions Based Programs Frank Function

From Frank Publication

Uploaded by

vickroid007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 7
f=isPerfect (n); if(f) System.out.println("It is a Perfect number") else System.out.println("It is not a Perfect number"); break; default: System. out.print1n ("Invalid Choice! tal Drill Tick (/) the correct option. 1. Oncea function is defined, it can be invoked repeatedly. What is this feature called? a. Interface © b. Reusability © 4. Allofthese 2. Ifa function does not return any value, its return type should be: . Restructuring O O a. int O b. no-eturn Oo void O 4. empty Oo 3. A function that computes a value and returned is called: a. Computational function (© ». Manipulative function oO c. Procedural function © 4. None of these Gs): |. The first line of the function definition is called: a. Function prototype ©) ». Function signature oO « Bothaandb © 4. None of these oO 5. The number of values that a function can return is: [ICSE 2023] ad Orb.2 oO “3 Oa 0 6. Which among the following is not a valid access specifier? a. public © ». private Oo <. partially © 4. protected Oo 7. The blueprint that defines the variables and the methods common to all of a certain kindis termed as: [ICSE 2021] a. class © bz object O c. package © 4. method O 8. Which of the following keyword is used to create symbolic constants in Java? [ICSE 2021] a. final © ». Final Gal c. Constant O 4 Cons Oo er-Defined Methods “145 145 . Uiese: it of an object oy led with help ') 9. A____ method needs to be cal eae a. void i gd. static hod call statemen 10, Parameters used in the met b._ Informal parameters a. Actual parameters 6 a. void parameters <. Formal parameters ; ims no value: 11, The keyword which indicates that the method retu ; ic a. public ©) set CO 4. abstract ic Nod one unit is called as: 12, The process of binding the data and method together 2 © ». Inheritance a. Encapsulation t O«4 Dynamic binding Polymorphism DG :GO 00.00 00 oO 13. Amethod which does not modify the value of variable is termed as: [icse. 203) a. Impure method b. Puremethod . Primitive method CO 4. User-defined method 14. Method which is a part of ‘class’ rather than an instance of the class istermedas: —[ICSE20) a. Static method O b. Non-static method c. Wrapper Class O 4. String mehtod B. Fillin the blanks. 1. In Java functions are known as 2. Methods are contained in 3. The function name and the parameter list together is known as 4, The access specifier, return type and the function signature together is known as 5. The arguments of the function given in function prototype are called 6. Parameters used in the mehtod call statement are parameters, [ICSE 2021). 7. Ifafunction does not return any value, the returning type in the function prototype willbe 8. Whena function is called by the values of actual parameters are copied into separate memory locations as allocated by the formal parameters. 9. Impure functions uses call by 10. One of the practical implementation of polymorphism is A. Answer the following questions. 1. What is a method? Write two advantages of using functions ina program, Explain the function of the ‘return’ statement, Classify functions depending upon the value it returns, Differentiate between Formal Parameter and Actual Parameter, State the difference between function Prototype and function signature. sy eyy ICSE Computer Appiictions? piel 7. Howare functions called? How does it return a value? 8. How are the following passed? (i) Primitive types (ii) Reference types 9. Differentiate between pure and impure function. 10. Explain function overloading with an example. 11, When there are multiple definit it Re ces ipl itions with the same function name, what makes them different from 12, What are the different access specifiers available in Java? write function prototypes for the following: |. Private access met “ 1 ‘thod sum which accepts three int type variables as parameters and return a float type. . Default acc "length" whi 2 ee "ess method "length" which accepts a String type variable as parameter and returns an int 3. Public access method "increment" which acc , e mobectun inital pts an object of Myclass type as parameter and does 4. Protected access method largest which accepts a float type, int type and double type data as parameters and have a byte type as return type. 5. Public access static method calculate which accepts a by i 2 and int type data type as pars id Loapeaireia pts a byt ‘ype data type as parameters ant ‘Answer as directed: 4. Inthe program given below: class MyClass { static int x = 7; int y = 2; public static void main(String argsf ]) { MyClass obj = new MyClass(); system.out.println(x); obj.sampleMethod(5); int a= 6; system.out.printin(a); } void sampleMethod(int n) { System.out.printin(n); system.out printin(y); } } State the name and value of the: (method argument or argument variable. User-Defined Methods m_ Gi) class variable. Gii) local variabie. I (iv) instance variable. i 2. Name the keyword which: (eSe5, ! (@ indicates that a method has no return type. 4 (ii) makes the variable as a class variable. ( Given below is a class with following specifications: i class name : Number ‘ void Display(intn) To extract and print each digit of given number from last digit of 4. digit on separate lines. ti Example: n= 674 ! Output | 4 7 i b 1 void Display() = To print numbers from 0.5 to 5.0 with updation of 0.5. Fill in the blanks of the given program with appropriate statements. class (i) void Display(int n) { while((ii) ) { int rem= (ii) System.out. printin(rem); na(iv), } Void Display({ forv)____jx=(vi)__; x+=0.5) System.out.printin(x); } () (@) Number (b) number (©) NUMBER (4) NUM (i) (a)n0 (c) ns=0 (4) n=o (iii) (a) n&100; (b) nto; (©) n%io; (4) nhtoo (iv) (a) n%10; (b) nfto; (©) nhtoo; (d) nxtoo (vy) (a) double x=0.5 (b) Double x=0.5 (©) double x=0.0 (d) Double x-00 (vi) (a) x>=5.0 (b) x<=5.0 (©) x==5.0 (d) x=5.0 Write programs for the following: 1. Create a function which accepts an inte; prime number or not. , scatoré" _)148 ICSE Computer Applicat yg ee _ ee | ise createa function which accepts an integer as parameter and return true if itis a perfect number CS rect return false. In the main() method input two Integers and check whether both the numbers are pel numbers or not. create a function which accepts an integer as parameter and return the sum of the cube of its digits: 17 3 ne main() method display all three digit Armstrong numbers. Create a function which accepts an integer as parameter and return true if it is a palindrome number + cherwise return false. In the main() method input 10 integers and print the largest palindrome number ifany. 5, Create a function which accepts an integer as parameter and return the sum of its digits. Create another function to Input 10 integers and find the sum of the digits of each number. 6, Create a function which accepts an integer as parameter and return the largest digit. Create another function to input 10 integers and find the sum of the largest digit of each number. 3. Create a class with the following methods: a. int sum(int n), which finds the sum of the digits inn and returns it. b. void call() to input 10 integers using scanner and find the sum of its digits of each integer value entered by the user using the above method. 8, Create a class with the following methods: a. boolean prime(int n), which returns true if nis prime otherwise returns false. b. void call() to input 10 integers using scanner and find the sum of those integers which are prime numbers using the above method. 9. Create a class with the following methods: a. boolean is Armstrong(int n), which returns true if n is Armstrong number otherwise returns false. Armstrong numbers are those numbers, whose sum of the cube of its digits is equal to the number. For example, 153=1+57+3? b. void call() to input 10 integers using scanner and find largest Armstrong number if any. 10, Create a class with the following methods: 2. boolean prime(int n), which returns true if nis prime otherwise returns false. b. int sum(int n), which finds the sum of the di innandreturns it. void call() to display all such three digit numbers, whose sum of the digits is a prime number. 11, Greate a class with the following methods: a. int LCM(int a,int b), which returns the least common multiple(LCM) among the two integers a and b and return it. b. void call() to input 10 integers and using the above function find the LCM among the 10 intgers. ‘2. Create a class with the following methods: a. int HCF(int a,int b), which returns the highest common factor(HCF) among the two integers a and b and return it. b. void call() to input 10 integers and using the above function find the HCF among the 10 intgers. Create a class called GeneratePrime which will be used to generate n number of prime numbers. The class should have the following methods: 8. User. Defined Methods weL_ Bie» ifiti Wy aparameter andretum trueifitis a prime, num, (i) Method called isPrime() which accepts an integer 25 wel otherwise return false. as Scanner input and display the fist x i (il) Method called display() which accepts an integer nels number by calling the above function. 14. Design a class to overload a function series( ) as follows: i a. _ void series (int x, int n) - To display the sum of the serie: KER Ha xO b. void series (int p) - To display the following series: ©, 7, 26, 63 terms : «void series ()- To ea the sum of the series given below: wa +13 +14 nA fe a 15. Create a function which accepts an integer as parameter and return een a : . ats ms digits, Create another function which accepts an integer as parameter an erm ue Ie happy otherwise return false. In the main input an integer and check whether it i ornot. ref (icse. 2019) { ' / given below: ee example 7=> (7"}=49=> (47+9*)}=97=>(9? +7*)=130 =>(¥? +3'+0")=10 =>(17+0")= 1. f 16. Write a class with the name volume using function overloading that computes the volume of a Cube, a sphere and a cuboid. f Formula: volume of a cube (vc) = s*s#s volume of a sphere (vs) = 4/3 * pi* r*r* r (where pi= 3.14 or 22/7) Volume of a cuboid (ved) =1* b *h 17. Design a class to overload a function num_cale( )as follows: i 2 void num_cale(int num,char ch) with one integer argument and one character argument, computes, the square of integer argument if choice chis's! otherwise find its cube, b. void num_calc(int a, int b,char ch) with two integer arguments if chis 'p' else adds the integers, © void num_calc(String s1,String s2) with two String arguments, equal or not. 18. Design a class to overload a function compute() as follows: 2. void compute(int,char): to compute the s argument is ‘s’ otherwise find its cube. which prints whether the strings ae! 1 ‘ware of the integer argument if the given character Volume of cube=side? Area of rectangle= Diagonal of cube=av3 length*breadth Perimeter of Fectangle=24(length+breadth) mber and check and display whether it is a Prime Number o" © SWitch-case statement), 2. Prime number: A number is said to be a prime number if any othernumber. Example 35.71nag Its divisible only by + and itself and not 19. Write a menu driven program to accept a nu not OR an Automorphic Number or not. (Us Sie ICSE Computer Applications? Vn b, Automorphic number: An automorphic number Is the of its square. Example: 25 Is an automorphic number a two digits. 20, Design a class to overload a method Number () as follows: a. Void Number (int num.int d) Example: num = 2565685 d=5 Frequency of digit 5 = 3 b. Void Number (int n1) Example: i= 29865, Sum of even digits = 16 Number which Is contained In the last digit(s) s Its square Is 625 and 25 Is present as the last [ICSE Specimen Paper] To count and display the frequency of a digit in a number. To find and display the sum of even digits of a number. Write a main method to create an object and invoke the aobve mehtods. 21. Design a class to overload a function volume() as follows: [ICSE 2019] a ire volume (double R) - with radius (R) as an argument, returns the volume of sphere using the formula. V= 4/3 x 22/7 xR? double volume (double H, double R) - with height(H) and radius(R) as the arguments, returns the volume of a cylinder using the formula, V=22/7xRXH double volume (double L, double B, double H) ~ with length(L), breadth(B) and Height(H) as the arguments, returns the volume of a cuboid using the formula. V=LxBxH 22. Define a class to overload to function print() as follows: * Void Print() To print the following format raat 2222 3333 4444 5555 * Void Print(int n) To check whether the number is a lead number. A lead number is the one whose sum of even digits are equal to sum of odd digits. eg. 3669 odd digits sum = 3 +9 =12 eg. 3669 even digits sum = 6 + 6 = 12 3669 is a lead number. [ICSE 2023] User-Defined Methods ‘Ast

You might also like