Thursday, 12 December 2013

Question Answer of chapter 12

QUESTIONS & ANSWERS on MySQL
Q.1. What is MySQL?
Ans:- It is an Open Source RDBMS Software. It is available free of cost.

Q.2. What is SQL?
Ans . SQL is Non-procedural universal data access language used to access and manipulate data stored in nearly all
the data bases available currently. SQL standards are defined by ANSI (American National Standards Institute). SQL
statements are used to retrieve and update data in a database. SQL works with database programs like MySQL, MS
Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc.

Q.3. Differentiate between DDL and DML?
Ans Data Definition Language (DDL): This is a category of SQL commands. All the commands which are used to
create, destroy, or restructure databases and tables come under this category. Examples of DDL commands are -
CREATE, DROP, ALTER. Data Manipulation Language (DML): This is a category of SQL commands. All the
commands which are used to manipulate data within tables come under this category. Examples of DML commands
are - INSERT, UPDATE, DELETE.

Q.4 What is a constraint?
Ans : A constraints is a condition or check application on a field or set of fields.
Example: NOT NULL (ensure that column con not have null value), CHECK (make sure that all
value satisfy certain criteria), UNIQUE (ensure that all values in a column are different) etc.

Q5 What are single row functions ?
Ans: Single Row Function work with a single row at a time. A single row function returns a result for
every row of a queried table.
Examples of Single row functions are Sqrt(), Concat(), Lcase(), Upper(), Day(), etc.

Q. 6 Compare CHAR and VARCHAR data types.
Ans. The CHAR data-type stores fixed length strings such that strings having length smaller than the
field size are padded on the right with spaces before being stored.
The VARCHAR on the other hand supports variable length strings and therefore stores strings
smaller than the field size without modification.

Q.7 What are the differences between DELETE and DROP commands of SQL?
Ans: DELETE is DML command while DROP is a DDL command. Delete is used to delete
rows from a table while DROP is used to remove the entire table from the database.

Q8 What do you understand by MySQL Server?
Ans:MySQL server listens for clients requests coming in over the network and accesses database contents
according to those requests and provides that to the client.

Q9 What do you understand by MySQL Client?
Ans:MySQL Clients are programs that connect to MySQL Server and issue queries in predefined format.

Q.10 Explain with the help of an example that why should a transaction be executed as a
whole or it should be not executed at all.
Ans: Suppose Raunak's account number is 3246 and his aunt's account number is 5135. In order
to process the cheque presented by Raunak, the following two SQL commands need to be
executed on the database maintained by the bank:
UPDATE Savings SET balance = balance - 2000
WHERE account_no = 5135;
UPDATE Savings SET balance = balance + 2000
WHERE account_no = 3246;
The above two Updates should both take place. If the first Update takes place and there is
a system failure, the first updation should be undone. Either both the updations should be done and if
it is not possible for both the updations to be done, then no updation should be done.

Query Based question & answers

1. The Pincode column of table 'Post' is given below-
.Pincode
10001
120012
300048
281001
i. SELECT Pincode from Post where Pincode LIKE " %1" ;
ii. SELECT Pincode from Post where Pincode LIKE " 0%" ;
Ans:
i) 110001 ii) No Output

2. A table "Animals" in a database has 3 columns and 10 records. What is the degree and
cardinality of this table?
Ans: Degree 3 and Cardinality=10

3. Answer the question based on the table VOTER given below:
Table : VOTER
Column Name                Data type                 Size                Constraints                 Description
V_id                               BIGINT                    8                   Primary key             Voter identification
Vname                            VARCHAR              25                  Not null                  Name of the voter
Age                                  INT                        3                   Check>17              Age should not less than                                                                                                                                 equal to 17
Address                         VARCHAR2           30                                                  Address of voter
Phone                             VARCHAR            10                                                 Phone number of the voter

(i) Write the command to delete all the rows of particular voter from the table voter where voter ID between
10 and 20.
Ans: Delete from VOTER where V_id between 10 and 20;

(ii) Delete the table physically.
Ans: Drop table VOTER;

4. . Write MySql command to create a furniture table including all constraint.
Table: Furniture
ITEMNO                ITEMNAME             TYPE           DATEOFSTOCK   PRICE         DISCOUNT
INT                         VARCHAR             VARCHAR       DATE                        INT                INT
5                               20                                20                                                     6                   2
PRIMARY KEY        NOT NULL                                   DEFAULT
                                                                                        ‘19/03/2010’
CREATE TABLE FURNITURE
( ITEMNO INT(5) PRIMARY KEY, ITEMNAME VARCHAR(20) NOT NULL,
TYPE VARCHAR(20),DATE_STOCK DATE DEFAULT '2012/03/19', PRICE INT(6), DISCOUNT INT(2) );

5. Consider a database LOANS with the following table:
Table: Loan_Accounts
AccNo        Cust_Name            Loan_Amount         Instalments      Int_Rate        Start_Date       Interest
1                  R.K. Gupta            300000                     36                 12.00           19-07-2009
2                  S.P. Sharma           500000                     48                 10.00           22-03-2008
3                  K.P. Jain                300000                    36                  NULL          08-03-2007
4                  M.P. Yadav            800000                    60                  10.00           06-12-2008
5                  S.P. Sinha               200000                    36                  12.50            03-01-2010
6                  P. Sharma                700000                   60                  12.50             05-06-2008
7                  K.S. Dhall               500000                    48                  NULL            05-03-2008

Answer the following questions.
Create Database and use it
1. Create the database LOANS.
Mysql> Create Database LOANS;

2. Use the database LOANS.
Mysql> Use LOANS;

Create Table / Insert Into
3. Create the table Loan_Accounts and insert tuples in it.
Mysql>Create table Loan_Acc (AccNo int primary key,
Cust_Name varchar(30), Loan_Amount int, Installment int, Int_Rate number(5,3),
Start_Date date, Interest number(7,2));

Mysql> Insert into Loan_Acc values(1,'R.K. GUPTA',300000,36,12.0.'2009-07-19');
Simple Select

4. Display the details of all the loans.
Mysql> Select * from Loan_Acc;

5. Display the AccNo, Cust_Name, and Loan_Amount of all the loans.
Mysql> Select Acc_No,Cust_Name,Loan_Amount from Loan_Acc;
Conditional Select using Where Clause

6 Display the details of all the loans with less than 40 instalments.
Mysql> Select * from Loan_Acc where Instalment <40;

7. Display the AccNo and Loan_Amount of all the loans started before 01-04-2009.
Mysql> Select AccNo, Loan_Amount from Loan_Acc where Start_Date <'2009-04-01'; 8. Display the
Int_Rate of all the loans started after 01-04-2009.
Mysql> Select Int_Rate from Loan_Acc where Start_date>'2009-04-01';

Using NULL
8. Display the details of all the loans whose rate of interest is NULL.
Mysql> Select * from Loan_Acc where Int_rate is NULL;

9. Display the details of all the loans whose rate of interest is not NULL.
Mysql> Select * from Loan_Acc where Int_rate is not NULL;

Using DISTINCT Clause
10. Display the amounts of various loans from the table Loan_Accounts. A loan amount should appear only
once.
Mysql> Select DISTINCT Loan_Amount from Loan_Acc;

11. Display the number of instalments of various loans from the table Loan_Accounts. An instalment should
appear only once..
Mysql> Select DISTINCT Instalment from Loan_Acc;

Using Logical Operators (NOT, AND, OR)
12. Display the details of all the loans started after 31-12-2008 for which the number of instalments are
more than 36.
Mysql> Select * from Loan_Acc where Start_Date>'2008-12-31' and Instalment>36;

13. Display the Cust_Name and Loan_Amount for all the loans which do not have number
of instalments 36.
Mysql> Select Cust_Name, Loan_Amount from Loan_Acc where Instalment <>36;

14. Display the Cust_Name and Loan_Amount for all the loans for which the loan amount
is less than 500000 or int_rate is more than 12.
Mysql> Select Cust_Name, Loan_Amount from Loan_Acc where Loan_Amount <500000 or
Int_rate>12;

15. Display the details of all the loans which started in the year 2009.
Mysql> Select * from Loan_Acc where Year(Start_Date)=2009;
16. Display the details of all the loans whose Loan_Amount is in the range 400000 to
500000.
Mysql> Select * from Loan_Acc where Loan_Amount between 400000 and 50000;

17. Display the details of all the loans whose rate of interest is in the range 11% to 12%.
Mysql> Select * from Loan_Acc where Int_Rate between 11 and 12;

Using IN Operator
19. Display the Cust_Name and Loan_Amount for all the loans for which the number of
instalments are 24, 36, or 48. (Using IN operator)
Mysql> Select Cust_Name, Loan_Amount from Loan_Acc where Instalment IN(24,36,48); UR
Using LIKE Operator

20. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name ends with 'Sharma'.
Mysql> Select AccNo, Cust_name from Loan_Acc where
Cust_Name like '%Sharma';

21. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the Cust_Name ends
with 'a'.
Mysql> Select AccNo, Cust_name,Loan_Amount from Loan_Acc where Cust_Name like '%a';

22. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name contains 'a'
Mysql> Select AccNo, Cust_name,Loan_Amount from Loan_Acc where
Cust_Name like '%a%';

23. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name does not contain 'P'.
Mysql> Select AccNo, Cust_name,Loan_Amount from Loan_Acc where
NOT (Cust_Name like '%P%');

24. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name contains 'a' as the second last character.
Mysql> Select AccNo, Cust_name,Loan_Amount from Loan_Acc where
Cust_Name like '%a_';

Using ORDER BY clause
25. Display the details of all the loans in the ascending order of their Loan_Amount.
Mysql> Select * from Loan_Acc ORDER BY Loan_Amount;

28. Display the details of all the loans in the descending order of their Start_Date.
Mysql> Select * from Loan_Acc ORDER BY Start_date DESC;

29. Display the details of all the loans in the ascending order of their Loan_Amount and within
Loan_Amount in the descending order of their Start_Date.
Mysql> Select * from Loan_Acc ORDER BY Loan_Amount, Start_Date DESC;

Using UPDATE, DELETE, ALTER TABLE
30. Put the interest rate 11.50% for all the loans for which interest rate is NULL.
Mysql> Update Loan_Acc SET Int_Rate =11.50 Where Int_Rate IS NULL:

31. Increase the interest rate by 0.5% for all the loans for which the loan amount is more than 400000.
Mysql> Update Loan_Acc SET Int_Rate= Int_Rate+0.5
Where Loan_Amount >400000;

32. For each loan replace Interest with (Loan_Amount*Int_Rate*Instalments) 12*100.
Mysql> Update Loan_Acc
SET Interest=(Loan_Amount*Int_Rate*Instalments) /12*100;

33. Delete the records of all the loans whose start date is before 2007.
Mysql> Delete From Loan_Acc Where Year(Start_Date)<2007;

34. Delete the records of all the loans of 'K.P. Jain'
Mysql> Delete From Loan_Acc Where Cust_Name='K.P.Jain';

35. Add another column Category of type CHAR(1) in the Loan table.
Mysql> Alter Table Loan_Acc ADD (Category CHAR(1) );

Find the Output of the following queries
36.SELECT cust_name, LENGTH(Cust_Name), LCASE(Cust_Name), UCASE(Cust_Name) FROM
Loan_Accounts WHERE Int_Rate < 11.00;

Cust_Name                    Length(Cust_Name)              LCASE(Cust_Name)            UCASE(Cust_Name)
S.P. Sharma                          11                                    s.p. sharma                         S.P. SHARMA
M.P. Yadav                          10                                     m.p. yadav                        M.P. YADAV

37.SELECT LEFT(Cust_Name, 3), Right(Cust_Name, 3), SUBSTR(Cust_Name, 1, 3) FROM
Loan_Accounts WHERE Int_Rate > 10.00;

LEFT(Cust_Name,3)           Right(Cust_Name, 3)            SUBSTR(Cust_Name, 1, 3)
R.K                                         pta                                     R.K
S.P                                         nha                                       S.P
P. R                                         ma                                       P.

38. SELECT RIGHT(Cust_Name, 3), SUBSTR(Cust_Name, 5) FROM Loan_Accounts;

RIGHT(Cust_Name, 3)                   SUBSTR(Cust_Name, 5)
pta                                                   Gupta
rma                                                   Sharma
ain                                                     Jain
dav                                                     Yadav
nha                                                   Sinha
rma                                                     harma
all                                                         Dhall

39. SELECT DAYOFMONTH(Start_Date) FROM Loan_Accounts;

DAYOFMONTH(Start_Date)
19
22
08
06
03
05
05

DDL and DML Commands(DBMS)

Chapter 16
Table Creation & DML Commands
TYPE A: VERY SHORT ANSWER QUESTION
1.  Which command is used for creating tables?
2.  Which is a constraint? Name some constraint that you can apply to enhance database
     
integrity.
3.  What is the role of UNIQUE constraint? How is PRIMARY KEY constraint different from
     
UNIQUE constraint?
4.  What is Primary key? What is PRIMARY KEY constraint?
5.  What is NOT NULL constraint? What are DEFAULT constraints?
6.  When column’s value is skipped in an INSERT command, which value is inserted in the
     
database?
7.  Can a column defined with NOTNULL constraint, be skipped in an INSERT command?
8.  How would you view the structure of table Dept?
9.  Table NewEmpl has same structure as that EMPL. Write a query to insert data from EMPL
table into NewEmpl, where salary is more than Rs 4000 and commission is greater than 500.
10. What is the error in following statement?
UPDATE EMPL;
TYPE B: SHORT ANSWER QUESTION
1.  How constraints ensure the validity of data? Explain various types of constraints with
     
example.
2.  What is FOREIGN key? How do you define foreign key in your table?
3.  How is FOREIGN KEY different from PRIMARY KEY command?
4.  What are table constraints? What are column constraints? How are these two different?
5.  What is default value? How do you define it? What is default value for a column for which no
     
value is defined?
6.  Differentiate between:
(i)        DROP TABLE & DROP DATADABASE
(ii)       DROP TABLE & DROP clause of ALTER TABLE.
7.  Consider the following table and answer the following-
Table: Empl
empno        ename               job            mgr         hiredate             sal           comm     deptno
8369     SMITH              CLERK            8902       1990-12-18         800.00         NULL          20
8499     Anya                SALESMAN     8839       1991-02-20        1600.00       300.00         30
8521     SETH               SALESMAN     8839       1991-02-22        1250.00       500.00         30
8566     MAHADEVAN  MANAGER       8844       1991-04-02        2985.00        NULL          20
8888     SCOTT             ANALYST        8566       1992-12-09        3000.00        NULL          20
8839     AMIR               MANAGER       8844       1991-11-18        5000.00        NULL          10
8844     Gates               PRESIDENT    NULL       1991-11-18        5000.00        NULL          10
….      ……….             ………              …..          ……….             …….           …..           ….

….      ……….             ………              …..          ……….             …….           …..           ….

a)  Update all Ename so that it contains the entire name in capital letters.
b)  Increase the salary of employee by 10% in Empl table.
c)  Give commission of Rs 500 to all employees who joined in year 1982 in Empl table
d)  Modify table Empl, add   another column called Grade of VARCHAR type size 1 into it.
e)  In the added column Grade, assign grade as follows.
if sal is in range   700-1500   Grade is 1
If sal is in range 1500-2200 Grade is 2
If sal is in range 2200-3000 Grade is 3
if sal is in range 3000- Grade is 4
f)   Display the details of employees who are working under the employee named AMIR.
g)  Modify the definition of column Grade. Increase its size to 2.
h)  Drop the table Empl.
8.  Given the following tables:
Orders (Ordno, Ord_date, ProdNo, Qty) Product (Prodno,Descp,Price)
Payment (OrdNo,Pment)
Write query statements for following transaction.
a)   Increase price of all products by 10 %.
b)   List the details of all orders. Whose payment is pending.
c)   Decrease price by 10% for all those products for which order were placed 10 months
      
before.
d)   Write a query to delete all those records from table Orders whose payment has been
      
made.
9.  Create the table Employee based on the following table instance Chart.
Column name     ID               FirstName              LastName                DeptID
Data Type            NUMBER   VARCHAR             VARCHAR              NUMBER
Length                8                25                          25                           8
10. Write the command for the following-
a)  Create table CUSTOMER as per following Table structure.
Column Name   CustID        CustName     CustAdd1      CustAdd2      CustPhone
Data Type          NUMBER    VARCHAR     VARCHAR    VARCHAR     VARCHAR
Length               7                 30                 20                 30                 10
b)    Add one column Email of data type VARCHAR and size 30 to table Customer.
c)  Add one more column CustIncomeGroup of data type VARCHAR(10).
d)  Insert few records with relevant information in the Customer table.
e)  Drop the column CustomerIncomeGroup from table Customer.
11. Create table Employee as per following Table structure.
Col. name          EmpID         EmpName       EmpAdd        EmpPhone    EmpSal       DeptID
Key type             Primary                                                                                           Foreign
Nulls /Unique                       NOT NULL
Fk Table                                                                                                                   Department
Fk Column                                                                                                               Dept_ID
Datatype            NUMBER    VARCHAR      VARCHAR     VARCHAR     NUMBER   VARCHAR
Length               6                 20                   30                 10                  9,2             2

Selection Control and Loop Control

Assignment Based on Selection Control and Loop Controls

1.      What is the difference between exit controlled and entry controlled  loop?
2.      Find out the value of variable b.
                int b=0 ;                                       
                for(int a=0;a<=30;a++)                                           
                     {
                         if( a % 2==0)
                             {                                                    
                                  b= b+a;                                                      
                           else
                               {                                                         
                                   b=b;                                                     
                                }}
                      System.out.println(“”+b);

3.      Write the sample code to check whether password is STUDENT or not if not display proper message “Password is wrong” ?


4.      What will be the value of Y if the value of  X is given  21                           
            (i)Y= ++ X;                 (ii) Y= X++;
5.      Rewrite the following program code using do…while loop                                     
                   int a, sum =0;
                   for (a=1; a< =50 ; a= a+2)
                   {
                        Sum = sum +a;
                   }
6.      The following code has some error(s).Rewrite the correct code underlining all the correction made:                                                                                  
                   Int I , sum = 0;
                   while ( I <= 20
                   {
                        Sum += i
                        i += 2;
                   }
                   jTextField1.getText ( “ “ +sum);
7.      What will be the contents of jTextField1 and jTextField2 after executing the following 
       Code                                                                                                                               
                   String str = “java GUI Programming”;
                   jTextFiled1.setText(str.tolowercase( ));
                   jTextField2.setText(str. Substring(5,8));
     8. Rewrite the   code using While Loop?                                       
         int j,i=5;
             for (j=1;j<=i;j++)
               {
      System.out.println( “ “+j);
                  }
     9.      What will be the contents of jTextarea1 after executing the following code:           
     
jTextarea1.setText(“Kendriya\n Vidyalaya\t Guna”);

     10.  Rewrite the code using switch statement:                                         
                             
                  If(k==1)
                              Day=”Monday”;
                  elseif(k==2)
                              Day=” Tuesday”;
                  elseif(k==3)
                              Day=” Wednesday”;
                  else
                              Day=”-”;
   11.  Rewrite the  following program code using a for loop:                     
Int i=1,sum=0;
While(i<10)
      {
                  sum+=i;
                  i+=2;
      }
   12.  The following has some error(s).Rewrite the correct code underlining all the corrections made:                                                                                                                 
Int i, j=5;
i==j+5;
if(i=j)
{
jtextfield1.setText(“I and j are unequal”);
                        jtextfield1.setText(“I and j are not equal”);breaks;
      }
else
                        jtextfield1.setText(“I and j are equal”)

    13.  What value for X below  will print Exactly “Line 20” lines to standard output:                                                                  
              int count=0;
            while(++count<X)
                        jTextField1.setText(“Line “ + count);
   14.  Rewrite the correct code underlining all the corrections made:                                                                                
int i; j=5;
i== j+5;
if(i=j)
{ jTextField1.setText(“i and j are unequal”);
jTextField2.setText(“they are not equal”); break;
}
else
jTextField1.setText(“i and j are equal”);

    15.  Rewrite the following program code using for loop:                                                 
int num=6;
int temp=num;
while(num>=1)
{ temp=temp-1;
if (temp%2==0)
System.out.println(“Is even”);
else
System.out.println(“Is odd”);
num=num-2;
}

    16.  Write the output of the program:                                                                                                                                1
                                    int x = 10;
                                    int y = 15;
                                    jTextField1.setText(“”+(x>y)? 3.14: 3);
    17.  What will be the contents of jTextField after executing the following statement?                              jTextField.setText ( ‘B’  + ‘a’ );

    18.  What will be the output of the program given below. Which number is printed twice? (Show the working also     
                                                int sum1=3;
                                                sum1++;
                                                jTextField1.setText(“”+sum);
                                                ++sum1;
                                                jTextField2.setText(“”+sum1);
jTextField3.setText(“”+(++sum1));
jTextField4.setText(“”+sum1++);
1jTextField5.setText(“”+sum1);

    19.  What will be the value of M and N after execution of the following code:                                                             
            int M=150,N;
            for(N=10;N<=12;N++)
                        M+=N;
            JOptionPane.showMessageDialog(this,”M : ” + M +”N: “+ N+””);

    20.  What will be values of x and y  after execution of the following code :                                           
                 int x, y = 0;
                 for( x= 1; x<=5; ++x)
                  y=x++;
                  --y;

   21.  Write a function in Java that takes principal, rate and time as parameter and returns Simple           
    Interest.

    22.  Rewrite the following code using a for loop :                                                                                                 
         int i=1, sum=0;
          while (i<10)
          {
           sum+=i;
           i+=2;
          }
    23.  Analyze the program segment and determine how many times the body of loop will be executed
x=5 ; y=50;                                                                                                                             
while (x<=y)
{ y=y/x;
jTextField1.setText (“” +y) ; }
    24.  Write a JAVA code that takes a character from JTextField1 and find whether it is a vowel or not and display it in JtextField2.         

    25.  State the output of the given code:                                                                           
int tick=10;
int k;
for(k=1; k<=10; k=k+2)
{   if (tick% k ==0 )
        jTextField1.setText( “ “+k + “ is a factor of “ + tick);
     else
 jTextField1.setText(Integer.toString(k));}
   26.  Rewrite the code  Using Switch case -                                                                                  
char c = ‘g’;
if(c = = ‘g’)
string x = “Greetings”  ;
if(c = = ‘b’)
    string x = “Bye” ;
if(c = = ‘d’)
    string x =   “ok”;
     else string x =  “Sorry! No Message Available”;
    27.  Name the method used to retrieve the selected item from  jComboBox.                             
    28.  What’s wrong with the while statement?                                                                              
while((ctr<5) &&(ctr>30))
{ int i=i++;}
    29.  double number;
string sn;
number= Double.parseDouble(jTextField1.getText( ));
JTextField2.setText(Integer.toString(sn.length( )));
    30.  How many variables and objects have been declared in the above code?                
    31.  Name any one native class along with its methods                            .                      
    32.  What will be the contents of jTextarea1 after executing the following code:                       
1.            jTextArea1.setText(“RED\n SCHOOL\t CHHUCHHAKWAS”);
    33.  Rewrite the following code fragment using switch :                                                             
            if(ch = = ‘E’)
                        east++;
            if(ch = = ‘W’)
                        west++;
            if(ch = = ‘N’)
                        north++;
            if(ch = = ‘S’)
                        south++;
            else
                JOptionPane.showMessageDialog(null, “unknown”);
   34.  Convert the following code into while loop.                                                                         
            int m,n;
            m=5; n=9;
for ( int j=0; j<=10; j+=2 )
            {
                        System.out.println( m + “ “ + n );
                        m = m + 10;
                        n = n + 5;
            }
    35.  Write two differences between a listbox and combobox.                                                     
    36.  The following code has some error(s). Rewrite the correct code and underlining all the corrections made:
int sum; value; inct;
int I;
for(i = = 0, i <= 10, i++)                                                                                                              
                  sum += i;
                  inct ++;                    
    37.   What will be the contents of jTextfield1 and jTextfield2 after executing the following code:        1
      String  s=”RED CHHUCHHAKWAS”
jTextField1.setText(s.Length()+”  “ );
jTextField2.setText(Math.pow(2,3)+“”);
    38.   What will be the value of x and y after execution of the following code:                           
int x , y = 0;
for(x = 1; x <= 5 ; x + + )
y = x + + ;
- -y;
System.out.println( x + “ “ + y );
    3 9.  Write a method in JAVA that takes a number as parameter and returns its reverse             
    40.  What is the output of the following code, if the value of variable k is 10?                                      
       int result = ++k + k++ + k ;
            System.out.println ( result ) ;
    41.  Write a program in JAVA to input a number in jTextField1 and calculate its factorial.       
   42.  What are expressions? How many types of expressions are there? Name them.                   
    43.  Differentiate between Entry-Controlled Loop and Exit-Controlled Loop.                          
    44.  Write the code for the following :                                                                                         
            1
            1 2
            1 2 3
            1 2 3 4
    45.  Given the following code fragment :                                                 
If(a==0)
System.out.println(“zero”);
If(a==1)
System.out.println(“one”);
If(a==2)
System.out.println(“two”);
If(a==3)
System.out.println(“three”);

Write an alternative code using switch case.
   46.  What will be the output produced by following code fragment?                 
x=1 ; y=1;
if(n>0) {

x=x+1 ;
y=y-1 ;
}
What will be the value of x and y, if n=1 & n=0
    47.  Find out errors if any:                                                                        
 int i; sum= 0;
i=1 ;
while (i<=10)
{
Sum =sum +i
i+=3
} System.out.println(sum) ;

   48.  Predict the output of the following code fragments:                                    
int val1 =5; val2=10;
for(int i=1;i<=3;i++)
system.out.println(“ “ +val1++  + “,” + --val2);
system.out.println(“ “ +val2--  + “,” +++va12);

    49.  Distinguish between a unary, a binary and a ternary operator, Give examples of Java operators for each one of them?                                                                     
   50.  What is wrong with following code:                                                                         
                       
            int n = 2
            Switch ( n)
            {
            Case 1:
                        a1 = 10;
                        a2 = 20;
                        break;
            Case 2:
                        a3 = 30;
                        break;
                        a4 = 40;
            }

    51.  What is the purpose of continue statement in loop?                                                  
   52.  Why is it necessary to put break statement after every case in a switch statement?  
    53.  How many times the following loops be executed:                                                   
                        LOOP-1                                  LOOP-2
                        int a=5,b=25;                           int a=5,b =25;
                        while (a >=b)                           while (a<=b)
                        {                                              {
                                    a = a + 10;                               a=a+10
                        }                                              }
   54.  Write a function in Java that accepts two numbers as Parameters and returns their product.                                                          
    55.  What will be the value of n after executing the following code:                                          
                        int n = 0;
                        if (6 >7 | | 5>4)
                        {
                                    n = 5;
                        }
                        else
                        {
                                    n = 7 ;
                        }

    56.  What will be the contents of jTextArea1 after executing the following statement?
                        jTextArea1.setText(“Hello \n How are You \t Rohit?”);
    57.  Rewrite the following code using while loop 2
                        int sum = 0; j = 5;
                        for (i=0;i<=4; i++)
                        {
                                    sum = sum +(i+j-1);
                        }
    58.  Identify the error(s) in the following code fragment:
                        int vowels = 0;
                        switch (ch)
                        {
                                    case „a‟ :
                                    case „A‟ :
                                    case „e‟ :
                                    case „i‟ :
                                    case „I‟ :
                                    case „o‟ :
                                    case „O‟ :
                                    case „u‟ :
                                    case „U‟ :vowels++;
                        }
    59.  What will be the contents of jTextField1 and jTextFiled2 after executing the following     code:                                                                                                                                      
                                    jTextField1.setText(Math.pow(3,4)+ “”);
                                    jTextField2.settext(Math.round(23.172)+ “”);
60.  Differentiate between a Text Field, Text Area and password field.
61.  What is the difference between if and switch statements?
62.  What are the operators supported by Java explain logical operators?
63.  Given the following expression:-
             a ) res= 30;             b ) res==30;
64.  What is the difference between these two statements?
65.  What will be the value of res if initial value of res is equal to 48
66.  Write a java code for the Item event handler of a checkbox(namely incCB) that increments a variable total and display it on a label(namely count) the checkbox is selected.

67.  State the output of the following code:                                                                                             
int   a = 10 , b = 5 ;
if ( a > b )  {
if ( b > 5 )
tf1. setText ( " b is " + b ) ;
}
else
tf1. setText ( "a  is " + a ) ;
68.  What will be the output of the following code fragment when the value of ch is ‘B’.                     
switch (ch) {
            case ‘A’ : ta1. append (" Grade A " );
  case ‘B’ : ta1. append (" Grade B " );                
            case ‘C’ : ta1. append (" Grade C " );                
            case ‘D’ : ta1. append (" Grade D " );
                 break ;
            default   : ta1. append (" Grade F " );
}
69.  Rewrite the following code using do-while loop.                                                                             
for ( i = 0 ; i < 10 ; i ++ )
  ta1. append ( 2 + " x " + i + " = " + ( 2 * i ) ) ;
70.  Rewrite the following program code using a switch statement :                                                       
if ( code = = 1 )
            Month = "January" ;
else if ( code = = 4 )
  Month = "April" ;
else if ( code = = 8 )
  Month = "August" ;
else
  Month =  "No Match" ;
71.  The following code has error(s). Rewrite the correct code underlining all the corrections made:           
int Sum = 0 , Step = 5 ;
int I ;
for ( i = 0 ; i < = 5 , i ++) ;
{
                        Step += 5 ,
  Sum += Step ;
}
jTextArea1 . showText ( "  " + Sum )
72.  Find error :-                                                                                                                                         1
              if (sex==1)
                     jLabel1.setText(“Male”);
              else ;
                      jLabel1.setText(“Female”)
73.  What will be the value of x and y after execution of following code :                                                          1
int  x , y = 0 ;
for ( x = 1 ; x < = 5 ;  ++x )
                          y = x + + ;
- - y ;
74.  What will be the value of P and Q after execution of the following code?                                                   1
            int P,Q=100;
            for(P=10; P<=12;P++)
            {
                        Q += P;
            }
            System.out.println(P);
            System.out.println(Q);
75.  Rewrite the following program code using a Switch statement:                                                       
            if( code == 1 )
                        Month = “January”;
            else if ( code == 2 )
                        Month = “February”;
else if ( code == 3 )
                        Month = “March”
else if ( code == 4 )
                        Month = “April”;
else
                        Month = “No Match”;
76.  What will be displayed in jTextField1 after executing the following code?                         
            int   m =  16;
            m = m + 1;
if  ( m < 15 )
            jTextField1.setText(Integer.toString(m));
else
            jTextField1.setText(Integer.toString(m+15));
77.  What will be the contents of jTextField1 after executing the following statement :
int n=20;
n=n-6;
if(n<10)
            jTextField1.setText(Integer.toString(n));
else
            jTextField1.setText(Integer.toString(n-2));
78.  The following code has some error(s). Rewrite the correct code underlining all the corrections made:                                                                                                                         
Int n1,n2=10;
n1=n2-5;
if(n1=n2)
            jTextField1.setText(“n1 and n2 are equal”);
else
            jTextField1.setText(“n1 and n2 are not equal”);

79.  The Admission No. of a student is stored in a variable strAdmno. Sugandha wants to store this admission  no. in an Integer type variable intAdmno. What java statement should she write to do this?                                                                                 
80.  Rewrite the following program using  a if statement.                                                            2
int c=jComboBox1.getSelectedIndex();
switch(c)
{          Case 0:  FinalAmt= billAmt;  break;
            Case 1:  FinalAmt= 0.9*billAmt;  break;
            Case2:  FinalAmt=0.8* billAmt;  break;
            default:  FinalAmt= billAmt;  break;
}

81.  How many times the following while loop get executed?                                                    
int p=5;
int q=36;
while(p<=q)
{          P+=6;
}         
82.  Given a string object named Salary having value as “55000” stored in it. Obtain the output of the following.                                                                                                             
JOptionPane.showMessageDialog(null,””+Salary.length()+Integer.parseInt(Salary)));