• Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Have any question?

(+91) 98222 16647
info@simplycoding.in
RegisterLogin
Simply Coding
  • Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Java

Short questions on Java Functions

  • Categories Java, Functions in Java, Functions
Short questions on Java Functions
  1. Give the output and what does this test function do?
public class output3
{
void test()
{
int n=5732,result=0;
do
{
result *= 10;
int digit = n%10;
result += digit ;
n = n/10;
}while(n>0);
System.out.println(“Output = ” + result);
}
}

Ans

2375                 (it reverse the number.)

  1. In the program given below, state the name and the value of the function :
    1. method argument or argument variable
    2. local variable
    3. class variable
    4. instance variable
class myClass{
static int x = 7; int y = 2;
public static void main(String args[] ){
myClass obj= new myClass();
System.out.println( x );
obj.sampleMethod(5);
int a = 6;
System.out.println( a );
}
void sampleMethod(int n){
System.out.println(n);
System.out.println(y);
}
}

Ans

    1. Method argument or argument variable is: n
    2. The class variable is : x
    3. The local variable is: a
    4. The instance variable is: y
  1. Write the prototype of a function ADD() for each of the following purpose:
    1. To return and integer value.
    2. To receive one integer, one double type argument and returns a double type value
    3. To receive a character and an integer as parameters and no returning
    4. To receive an integer as parameter and returns true or false.

Ans.

    1. public int ADD) or public static int ADD) or int ADD)
    2. public double ADD ( int y, double m) or public static double ADD( int y, double m) or double ADD( int y, double m)
    3. public void ADD( char ch, int y) or public static void ADD( char ch, int y) or void ADD( char ch, int v)
    4. public boolean ADD( int y) or public static boolean ADD( int y) or boolean ADD( int y)
  1. Write the prototype of a method stud() which takes a string argument and a character argument and returns an integer.

Ans.

public static int stud ( String str, char ch ) OR
public int stud ( String str, char ch) OR
int stud ( String str, char ch)
  1. Write the prototype of a function Count which takes character argument and string argument and returns a true or false.

Ans.

public static boolean Count( char ch, String str ) OR
public boolean Count (char ch, String str) OR
boolean Count(char ch, String str )
  1. What are the values of a and b after the following function is executed, if the values passed are 30 and 50:
void paws(int a, int b)
{
a = a + b;
b = a – b;
a = a – b;
}

Ans. a=50 and b=30

  1. In the program given below, state the name and the value of the :
    1. method argument or argument variable
    2. local variable
    3. class variable
    4. instance variable
class myClass{
static int x = 7; int y = 2;
public static void main(String args[] ){
myClass obj= new myClass();
System.out.println( x );
obj.sampleMethod(5);
int a = 6;
System.out.println( a );
}
void sampleMethod(int n){
System.out.println(n);
System.out.println(y);
}
}

Ans.

    1. Method argument or argument variable is: n
    2. The class variable is : x
    3. The local variable is: a
    4. The instance variable is: y
  1. Write a small program code to show function call by value method.

Ans.

class program{
public static void simply( int a, int b){
a= a/2;
b= b+10;
System.out.println("The value of A = " + a +" and B " + b);
}
public static void run(){       // this function calls the above function simply()
int x= 20, y= 10;
simply(x, y);                //calling  function simply()
}
  1. Give the prototype of a function search which receives a sentence snt and a character ch and returns 1 or 0 ?

Ans.

public int function ( String snt, char ch )

  1. Write a function prototype of the following:

A function PChar which takes an integer argument and a character argument and returns an integer value.

Ans.    public int PChar(int n, char c)

  • Share:
author avatar
Simply Coding

Previous post

Questions on Class as the Basis of all Computation
June 11, 2020

Next post

Java character class example questions
June 11, 2020

You may also like

Functions or methods Programs 1
Functions or methods Programs
22 June, 2021
User – defined Methods
User – defined Methods
5 June, 2021
Crack Java Math Problems
Forming Math Expressions
13 June, 2020

Leave A Reply Cancel reply

You must be logged in to post a comment.

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String
Simply Coding Computer Courses for School                Privacy Policy     Terms of Use     Contact Us

© 2021 Simply Coding

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now