Storing and Operating on Data

Multiple Choice Questions

1     1. Which one of the following options is an example of char data type ?

a.      2                                                b.           
c.      23.3                                           d.            interest

1     2. The expression 9%2 evaluate to :

       a.      3                                               b.            5
c.      1                                               d.            4

2     3.  In Java, ‘*’ refers to

a.     Division                                    b.            Multiplication
c.     Modulus operator                     d.            Addition
3     4. Which one of the following operators is used to compare two expressions ?

a.     Relational operator                b.            Arithmetic operator
c.     Assignment operator                d.            Compound assignment operator

4     5. Which one of the following operators is not an arithmetic operator ?

a.      +                                              b.            %
c.      *                                              d.            && 

True of False :-

1       1. The double data type takes values such as 3.22 and 4.32.              TRUE
2       2. The ! operator is basically used to give the opposite boolean value of its operand.            TRUE
3       3.  int t; is known as initializing the variable.               FALSE
4       4. The use of the assignment operator allows you to modify the variable’s current value.     TRUE
5       5. The char data type refers to floating point.          FALSE

Subjective Questions:-

1     1. Discuss the use of variables ?
          Ans:- Variables are named storage location, that is used to store data for future use.

2     2. Give the syntax for declaring variable along with examples.
     Ans:-
                Syntax :-
                                <data type> <variable name>
                ex:-          int           t;
                                char       ch;
                                double   d;

3      3. Give examples of different data type used in Java.
            Ans :-  Some frequently used data type with examples are :
int  : This data type is used to define variables that stores integer values.
                for example : 3,4,5 etc.
float : This data type is used to define variables that stores floating point numbers. i.e they
           can  take decimal values.
                for example : 2.43, 7.56, 5.03
double : This data type is used to define variables that store BIG floating point numbers.
                for example : 85342.4433, 98786.7786
char : This data type stores single character value.
                for example : a,b,c,D
boolean : This data type is used to store either true or false.
                for example : true, false

4      4. What are operators and their functions?
      Ans :-  Operator is a symbol that tells the compiler to perform the specific task.
Some operators used by Java and their functions are as follows :-
(i)        Arithmetic Operator :- Addition(+), Subtraction(-), Multiplication(*), Division(/) and Modulus(%) is known as arithmetic operators.

The function of this operator is to perform mathematical calculations.

(ii)       Relational Operators :- Equal to(==), Not equal to (!=), Less than(<), Greater than(>), Less than or equal to (<=) and Greater than or equal to(>=) is known as relational operators.

The function of this operator is to compare two or more expressions.

(iii)      Assignment Operator :- The single equal (=) symbol is known as assignment operator.

The function of this operator is to assigns a value to a variable.

(iv)      Logical Operators :- AND(&&), OR(||) and NOT(!) is known as logical operators.
The function of AND – OR operator is to compare two relational operators to obtain a single relational result either true or false.

The function of NOT operator is to inverse resultant value.
               
5      5. Explain arithmetic operators.
      Ans :- Arithmetic operators perform mathematical calculations. Some of the arithmetic operators                   used by Java are as follows :-
                               
Operator
Description
+
addition
-
subtraction
*
multiplication
/
division
%
modulus/remainder

Lab Questions :

1. Write a program to illustrate the use of all arithmetic operations.

class Arithmetic_operations
{
    public static void main(String arg[])
    {
        int a = 3 + 4;
        int b = a * 4;
        int c = b - a;
        int d = b / 2; 
        int  e = b%2;                 
   System.out.println("a = " + a);
   System.out.println("b = " + b);
   System.out.println("c = " + c);
   System.out.println("d = " + d);   
        System.out.println("e = " + e); 
    }
}

2. Write a program to calculate the age of a person.
3. Write a program to find the area of rectangle.
Ans :-
import  java.util.Scanner;
class   AreaOfRectangle
    {
    public  static  void  main (String[]  args)
        { 
        double  length, width, area;
        Scanner  sc = new  Scanner(System.in);
        System.out.println("Enter the length of Rectangle:");
        length =  sc.nextDouble();
        System.out.println("Enter the width of Rectangle:");
        width =  sc.nextDouble();
        area = length*width;
        System.out.println("Area of Rectangle is :"+area);
        }
    }




0 comments:

Post a Comment