0% found this document useful (0 votes)
27 views70 pages

Class Xii Records

Uploaded by

harisivam01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views70 pages

Class Xii Records

Uploaded by

harisivam01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 70

PROGRAM : 01

RELATION –STUDENT
(Create, Insert, View, Delete)

1. Write the SQL queries for the following questions relation STUDENT below

S.n Name Class Se Result School


o c Name
1 Arun XII B1 Pass Dr.NKVV
2 Magesh XII D Pass Dr.NKVV
3 Velu XII C Fail BV
4 Vanitha X A Pass Ebenezer
5 Balu XII B Pass Dr.NKVV

1. Create table for the above mentioned sno is primarykey.


2. Insert the records as permentioned
3. To display all records from thetable
4. To display those records of passedstudents
5. To display student name, class, schoolname from the tablestudent.
6. Delete the record of student detail belongs to BV.
QUERIES

mysql>CREATE DATABASE
itpracticals; mysql>USE
itpracticals;
1. Create table for the above mentioned sno is primarykey.

mysql> CREATE TABLE STUDENT (SNO INTEGER PRIMARY KEY,NAME


CHAR(20),CLASS CHAR(5),SEC CHAR(2),RESULT
CHAR(15),SCHOOLNAME CHAR(30));
2. Insert the records as permentioned

mysql>insert into student


Values(1,”ARUN”,”XII”,”B1”,”PASS”,”DR.NKVV”); mysql>insert
into student Values(2,”Magesh,”XII”,”D”,”PASS”,”DR.NKVV”);
mysql>insert into student Values(3,”Velu”,”XII”,”C”,”Fail”,”BV”);
mysql>insert into student
Values(4,”Vanitha”,”X”,”A”,”Pass”,”Ebenezer”); mysql>insert
into student Values(5,”Bala”,”XII”,”B”,”Pass”,”Dr.NKVV”);
3. To display all records from the table student.
mysql>SELECT * FROMSTUDENT;

+ + + + + + +
| SNO|NAME | CLASS | SEC | RESULT | SCHOOLNAME|
+ + + + + + +
| 1 |ARUN | XII |B1 |PASS | DR.NKVV |
| 2 | Magesh |XII |D |PASS |DR.NKVV |
| 3 |Velu |XII |C |Fail |BV |
| 4 | Vanitha |X |A | Pass |Ebenezer |
| 5 |Bala |XII |B | Pass |Dr.NKVV |
+ + + + + + +
5 rows in set (0.03sec)

4. To display those records of passedstudents.


mysql> SELECT * FROM STUDENT WHERE RESULT="PASS";
+ + + + + + +
| SNO|NAME | CLASS | SEC | RESULT | SCHOOLNAME|
+ + + + + + +
| 1|ARUN | XII | B1 |PASS |DR.NKVV |

| 2 | Magesh|XII |D |PASS |DR.NKVV |


| 4 | Vanitha|X |A |Pass |Ebenezer |
| 5|Bala |XII |B |Pass |Dr.NKVV |

+ + + + + +
+ 4 rows in set (0.03sec)
5. To display student name, class, school name from the tablestudent.
mysql>Select name, class, schoolname from student ;

6. Delete the record of student detail belongs to BV.


mysql>Delete from student where schoolname=”BV”;
PROGRAM :0
2
RELATION –EMPLOYEE
Consider the following Employee table:

Table Name: Employee

The primary key of the table is Employee ID and Manager ID is the foreign key that
references Employee ID
Write SQL commands for the following:
1. Create the above table.
2. Insert values as shownabove.
3. Update the salary of “Amyra” to40000.
4. Alter the table Employee by adding a new columnphone_num.
5. Write a query to display names and salaries of those employees whose
salary are greater than20000.
6. Write a query to display name,salary and bonus details of employees in
descending order ofsalary.
7. Write a query to display the names of employees whose name contains “a” as
thelast
alphabet.
8. Write a query to display the name and Job title of those employees
whoseManager_ID is 1201.
9. Write a query to display the name and Job title of those employees whose
Manager is
“Amyra”.
10. Write a query to display the name and Job title of those employees aged
between 26 years and 30 years (bothinclusive)
QUERIES

1. Create the abovetable.


mysql> CREATE TABLE EMPLOYEE(EMPLOYEE_ID INTEGER PRIMARY KEY,EMPLOYEE_NAME
CHAR(20),JOB_TITLE CHAR(20),SALARY INTEGER,BONUS INTEGER,AGE INTEGER,MANAGER_ID INTEGER);
Query OK, 0 rows affected (0.06 sec)

2. Insert values as shownabove.


mysql>INSERT INTO EMPLOYEE VALUES (1201,”DIVYA”,”PRESIDENT”,50000,NULL ,29,NULL);
Query OK, 1 row affected (0.03 sec)
mysql>INSERTINTOEMPLOYEEVALUES(1205,”AMYRA”,”MANAGER”,30000,2500,26,1201);
Query OK, 1 row affected (0.03 sec)
mysql> INSERT INTO EMPLOYEE VALUES (1211,”RAHUL”,”ANALYST”,20000,1500 ,23,1205);
Query OK, 1 row affected (0.02 sec)
mysql> INSERT INTO EMPLOYEE VALUES (1213,”MANISH”,”SALESMAN”,15000,NULL,22,1205);
Query OK, 1 row affected (0.03 sec)
mysql>INSERTINTOEMPLOYEEVALUES(1216,”MEGHA”,”ANALYST”,22000,1300,25,1201);
Query OK, 1 row affected (0.03 sec)
mysql> INSERT INTO EMPLOYEE VALUES (1217,”MOHIT”,”SALESMAN”,16000,NULL,22,1205);
Query OK, 1 row affected (0.01 sec)

3. Update the salary of “Amyra” to40000.


mysql> UPDATE EMPLOYEE SET SALARY = 40000 WHERE EMPLOYEE_NAME="AMYRA";
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0

4. Alter the table Employee by adding a new


columnphone_num. mysql> ALTER TABLE EMPLOYEE ADD
(PHONE_NUM INTEGER); QueryOK,6rowsaffected(0.08sec) Records: 6
Duplicates: 0 Warnings:0
5. Write a query to display names and salaries of those employees whose
salary are greater than20000.
mysql> SELECT EMPLOYEE_NAME,SALARY FROM EMPLOYEE WHERE SALARY>20000;

+ + +
|EMPLOYEE_NAME | SALARY |
+ + +
| Divya | 50000
|
| Amyra | 40000
|
| Megha | 22000
|
+ + +
3 rows in set (0.00sec)
6. Write a query to display name,salary and bonus details of
employees in descending order ofsalary.
MYSQL> SELECT EMPLOYEE_NAME,SALARY,BONUS FROM EMPLOYEE ORDER BY
SALARY DESC;
+ + + +
| employee_name | salary | bonus |
+ + + +
| Divya | 50000 | NULL|
| Amyra | 40000 | 2500|
|Megha | 22000 | 1300 |
|Rahul | 20000 | 1500|
| Mohit | 16000 | NULL|
| Manish | 15000 | NULL|
+ + +
+ 6 rows in set
(0.00sec)
7. Write a query to display the names of employees whose name contains “a”
as the
lastalphabet.
mysql> SELECT EMPLOYEE_NAME FROM EMPLOYEE WHERE EMPLOYEE_NAME
LIKE("%A");
+ +
| EMPLOYEE_NAME|
+ +
| Divya |
| Amyra |
|Megha |
+

+ 3 rows in set (0.00


sec)

8. Write a query to display the name and Job title of those


employees whose Manager_ID is1201.
mysql>SELECT EMPLOYEE_NAME,JOB_TITLE FROM EMPLOYEE
WHERE MANAGER_ID =1201;
+ + +
| EMPLOYEE_NAME|JOB_TITLE |
+ + +
| Amyra |Manager |
|Megha | Analyst |
+ +
+ 2 rows in set
(0.00sec)

9. Write a query to display the name and Job title of those employees whose
Manager is“Amyra”.
mysql> SELECT EMPLOYEE_NAME,JOB_TITLE FROM EMPLOYEE
WHERE EMPLOYEE_NAME="Amyra" AND
JOB_TITLE="MANAGER";
+ + +
| EMPLOYEE_NAME | JOB_TITLE|
+ + +
| Amyra | Manager |
+ +
+ 1 row in set
(0.00sec)
10. Write a query to display the name and Job title of those
employees aged between 26 years and 30 years (both
inclusive)

mysql> SELECT EMPLOYEE_NAME,JOB_TITLE FROM EMPLOYEE WHERE AGE


BETWEEN 26 AND 30;
+ + +
|EMPLOYEE_NAME |JOB_TITLE |
+ + +
| Divya | President |
| Amyra | Manager |

+ +
+ 2 rows in set
(0.01 sec)
PROGRAM :03
RELATION –STOCK
(Aggregated Functions, Arithmetic
Operartor)
Consider the following the table

Itno Inam Price Stock Do


e p
111 Pencil 15 100 2020-01-20
222 Ruled Note 25 100 2020-02-01
333 Un-Ruled Note 45 75 2019-05-21
444 Sketch 25 100 2018-05-22
555 Box 15 100 2018-05-22
666 A4 Sheets 160 1000 2016-01-10
777 A4 Sheets 125 500 2016-01-10
777 A3 Sheets 155 200 2016-01-10

1. Calcualte price x stock as Total cost of product of relationtable.


2. Display the sum ofstock
3. Display the total items availaible in thestock
4. Display maximum price from stockdetails
5. Display the minimum price form stockdetails
6. Display maximum and minumim price of each item instock.
7. Display the latest productpurchased
8. Display the oldest stock in thestock.
9. Display the average amount of stock (price * stock).
10. Illustarte examples of AritmeticOperators)
1. Calcualte price * stock as Total Amount of product of relationtable.
mysql>SELECT INAME, PRICE*STOCK "TOTAL AMOUNT" FROM STOCK;
+ + +
| iname | Total Amount|
+ + +
| Pencil | 1500 |
| Ruled Note | 2500 |
| un-Ruled | 3375 |
Note
| Sketch | 2500 |
| Box | 1500 |
| A4-Sheets | 160000
|

+ + +
6 rows in set (0.00sec)

2. Display the sum ofstock

mysql>SELECT SUM(STOCK) FROM STOCK;

+ +
| sum(stock)|
+ +
| 1475 |
+ +

1 row in set (0.00sec)


3. Display the total items available in the Stock relation
mysql> select count(stock) fromstock;
+ +
| count(stock) |
+ +
| 6 |
+ +
1 row in set (0.00sec)
4. Display maximum price from stock
details. MYSQL>SELECT MAX(PRICE)
FROMSTOCK;
+ +
| max(price) |
+ +
| 160 |
+ +
1 row in set (0.00 sec)

5. Display minimum price from stock details.


mysql> select min(price) fromstock;

+ +
| min(price)|
+ +
| 15|
+ +

1 row in set (0.00 sec)

6. Display maximum and minumim price of each item instock.


MYSQL>SELECT INAME,MAX(PRICE),MIN(PRICE) FROM STOCK GROUP BY INAME;
+ + + +
| iname | max(price) | min(price) |
+ + + +
| A3-Sheets | 155 155 |
|
| A4-Sheets | 160 125 |
|
| Box | 15 | 15 |
| Pencil | 15 | 15 |
| Ruled Note | 25 | 25 |
| Sketch | 25 | 25 |
| un-Ruled | 45 | 45 |
Note
+ + + +
7 rows in set (0.00sec)
7. Display the latest product purchased
mysql> select max(dop) fromstock;
+ +
|mAX(dop) |
+ +
| 2020-02-01 |
+ +
1 row in set (0.00 sec)

8. Display the oldest stock in thestock.

mysql> SELECT MIN(DOP) FROM STOCK;


+ +
|min(dop) |
+ +
| 2016-01-10 |
+ +
1 row in set (0.00 sec)

9. Display the average amount of stock (price *stock).

mysql>SELECT AVG(PRICE*STOCK) FROM STOCK;


+ +
| avg(price*stock) |
+ +
| 33109.3750|
+ +
1 row in set (0.00
sec)
10. Illustrate ArithemeticOperators

Arithemetic Operators Example


mysql>SELECT (56+89);
+ +
| (56+89) |
+ +---------+
| 145 |
+ +
1 row in set (0.00 sec)
mysql> select (56+89);
+---------+
| (56+89) |
- +---------+
| 145|
+---------+
1 row in set (0.00 sec)
mysql> SELECT (56+89);
+ +
| (56+89) |
* +---------+
| 145 |
+ +
1 row in set (0.00 sec)
mysql> SELECT (100 /25);
+ +
| (100 /25)|
/ +-----------+
| 4.0000|
+ +
1 row in set (0.00 sec)
mysql> select (100 % 25);
+ +
| (100 % 25) |
% +------------+
| 0|
+ +
1 row in set (0.00 sec)
mysql> SELECT
(5+(156*(100))-(30+50)/10);
+ +

Combination | (5+(156*(100))-(30+50)/10) |
+ +
| 15597.0000|
+ +
1 row in set (0.00 sec)
PRACTICAL:
04
RELATION –TEACHER
(SELECT &UPDATE )
Consider the following table Teacher and answer for the following questions

Teacher_ID First_Name Last_Name Gender Salary Date_of_Birt Dept_No


h
1001 Lakshmi Narayana M 25000 1997-02- 111
n 15
1002 Balaji Mohan M 5000 1998-03- 222
18
1003 Lakshmi Narasiman M 150000 1994-02- 111
14
1004 Elizebath Maria F 25000 1998-05- 333
14
1005 Anitha NULL F 15000 1996-06- 333
18
1006 Beena Rajan F 18000 1980-05- 222
18

1. Insert a new record with thevalues


(1007,"Bharat", "Kumar", 'M', 50000, '1984-08-11', 222);
2. Update salary as 35000 with teacher ID1002
3. Increase the salary with 2500 of those teacher working in 222department.
4. To display the names of all teachers earning more than25000.
5. To display Teacher_ID,dept_no,First_Name,Last_Name and Dept_No of teachers
who belongs to department number 111 or333
6. To retrieve names of all the teachers starting from letter 'L’ along with thesalary.
7. To retrieve names of all the teachers having 5 characters in
the first name and starting with 'B' along with thedept_no.
8. To list the names,salary of teachers in alphabeticalorder.
9. To list the names,salary of teachers according to the seniority wise with respect
to birthday date.
10. To retrieve all the details of those employees whose last name is notspecified.
11. To retrieve the names of all the departments having femaleteachers.
12. To display 10% increase in salary as newsalary
13. To display number of teachers working in departmentwise.
14. To display the department id (ignoring therepeated).
15. Delete the teachers details with department id222
QUERIES

1. Insert a new record with thevalues


(1007,"Bharat", "Kumar", 'M', 50000, '1984-08-11', 222);
mysql> INSERT INTO TEACHER VALUES(1007,"BHARAT", "KUMAR",
'M', 50000, '1984-08-11', 222);
QUERY OK, 1 ROW AFFECTED (0.03 SEC)

2. Update salary as 35000 with teacher ID 1002.


mysql> UPDATE TEACHER SET SALARY=35000 WHERE TEACHER_ID=1002;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0

3. Increase the salary with 2500 of those teacher working in 222department.


mysql> UPDATE TEACHER SET SALARY=SALARY+2500 WHERE
DEPT_NO=222; QUERY OK, 3 ROWS AFFECTED (0.03 SEC)
Rows Matched: 3 Changed: 3 Warnings: 0

4. To display the names of all teachers earning more than25000.


mysql>SELECTFIRST_NAME,LAST_NAMEFROM TEACHER
WHERE SALARY>25000;
+ + +
| first_name | last_name |
+ + +
| Balaji | Mohan |
| Bharat | Kumar |
+ + +
2 rows in set (0.00 sec)
5. To display Teacher_ID,dept_no,First_Name,Last_Name and Dept_No of
teachers who belongs to department number 111 or333
mysql>SELECTTEACHER_ID,DEPT_NO,FIRST_NAME,LAST_NAMEFROM TEACHER
WHERE
DEPT_NO =111 ORDEPT_NO=333;
+ + + + +
| teacher_id | dept_no | first_name | last_name |
+ + + + +
| 1001 | 111 |Lakshmi |
Narayanan|
| 1003 | 111 |Lakshmi |
Narasiman|
| 1004 | 333 |Elizebath |Maria |
| 1005 | 333 |Anitha | |
+ + + +
+ 4 rows in set (0.00 sec)

6. To retrieve names of all the teachers starting from letter 'L’ along
withsalary.
mysql> SELECT FIRST_NAME,LAST_NAME,SALARY FROM TEACHER WHERE
FIRST_NAME LIKE("L%");
+ + + +
| first_name | last_name|salary |
+ + + +
|Lakshmi | Narayanan | 25000.00|
|Lakshmi | Narasiman | 15000.00|
+ + +
+ 2 rows in set
(0.00 sec)

7. To retrieve first names of all the teachers having 5


characters in the first name and starting with 'B' along with
their dept_no of malestaff.
mysql> SELECT FIRST_NAME,DEPT_NO FROM TEACHER WHERE FIRST_NAME LIKE("B
") ANDGENDER='M';
+ + +
| first_name | dept_no|
+ + +
|Balaji | 222 |
|Bharat | 222 |
+ +
+ 2 rows
in set (0.00 sec)

8. To list the names,salary of teachers in alphabeticalorder.


mysql> SELECT FIRST_NAME,SALARY FROM TEACHER ORDER BY (FIRST_NAME);
+ + +
| first_name|salary |
+ + +
|Anitha | 15000.00|
|Balaji | 37500.00|
|Beena | 20500.00|
|Bharat | 52500.00|
| Elizebath | 25000.00|
|Lakshmi | 25000.00|
|Lakshmi | 15000.00|
+ +
+ 7 rows
in set (0.00sec)

9. To listthenames,salaryof teachers according to the birthdaydate.


mysql> SELECT FIRST_NAME,SALARY,DATE_OF_BIRTH FROM TEACHER ORDER BY
(DATE_OF_BIRTH);
+ + + +
| first_name|salary | date_of_birth|
+ + + +
| Beena | 20500.00 | 1980-05- |
18
| Bharat | 52500.00 | 1984-08- |
11
| Lakshmi | 15000.00 | 1994-02-14 |
| Anitha | 15000.00 | 1996-06-18 |
| Lakshmi | 25000.00 | 1997-02-15 |
| Balaji | 37500.00 | 1998-03- |
18
| | 25000.00 | 1998-05- |
Elizebath 14
+ + +
+ 7 rows in set (0.00
sec)
10. To retrieve all the details of those employees whose last
name is not specified.
mysql>SELECT* FROM Teacher WHERE Last_Name ISNULL;
+ + + + + + + +
| Teacher_ID | First_Name | Last_Name | Gender | Salary | Date_of_Birth | Dept_No |
+ + + + + + + +
| 1005 |Anitha |NULL |F | 15000.00|1996-06-18 | 333|
+ + + + + + +
+ 1 row in set (0.00 sec)
11. To retrieve the names of all the departments having femaleteachers.
mysql> SELECT DEPT_NO,FIRST_NAME FROM TEACHER WHERE GENDER="F";
+ + +
| dept_no | first_name|
+ + +
| 333 | Elizebath |
| 333 | Anitha |
| 222 | Beena |
+ +
+ 3 rows in
set (0.00 sec)
12. To display name ,salary and newsalary 10% increment of
salary of those teaches working in dept_no 222.
(Increment is calculated as
salary*10/100,Newsalary=salary+increment)

mysql> SELECT FIRST_NAME,SALARY,SALARY*10/100 AS


INCREMENT,SALARY+SALARY*10/100 AS NEWSLARY
FROM TEACHER WHERE DEPT_NO=222;
+ + + + +
| FIRST_NAME | SALARY|INCREMENT |NEWSLARY |
+ + + + +
|Balaji | 37500.00 | 3750.000000 |
41250.000000|
|Beena |20500.00 | 2050.000000 |
22550.000000|
|Bharat | 52500.00 | 5250.000000 |
57750.000000|
+ + + +
+ 3 rows in set (0.00 sec)

13. To display number of teachers working in departmentwise.

mysql> SELECT DEPT_NO, COUNT(DEPT_NO) FROM TEACHER


GROUP BY (DEPT_NO);
+ + +
|dept_no | count(dept_no)|
+ + +
| 111 | 2 |
| 222 | 3 |
| 333 | 2 |
+ +
+ 3 rows in set
(0.00 sec)
14. To display the department id (ignoring therepeated).

mysql> SELECT DISTINCT(DEPT_NO) FROM TEACHER;


+ +
| dept_no |
+ +
| 111 |
| 222 |
| 333 |
+ +
3 rows in set (0.00 sec)

15. Delete the teachers details with department id222


mysql> DELETE FROM TEACHER WHEREDEPT_NO=222;
Query OK, 3 rows affected (0.04 sec)
PROGRAM :
05
SQL-AGGREGATE FNCTIONS

Consider the following tables

Table :STORE

Table: SUPPLIERS

AIM : To write SQL queries and outputs using built-in


aggregate functions such as COUNT,SUM, MAX,MIN and
AVG.
1. To display the number of records in the tablestore
2. To display the no of item’s from the table store whose item
names starting with‘G’

3. To count and display the scode from the table store(avoidduplicate)

4. To display the maximum and minimum rate of items for each


supplier individually as per scode from the table store from
the tablestore.

5. To display the total quantity of the items from the tablestore.


6. To display the average rate of the items from the tablestore.

7. To display the no of items for each supplier as per scode from the
tablestore.

8. To display the no of items for each supplier from the table


store whose number of item is greater than2

9. To display the number of items for each supplier with their


name as per scode from the table store.
PROGRAMMING IN JAVA
PROGRAM :0
1

1. Write a java program to calculate the area of a rectangle.

AIM :To calculate the area of a rectangle using the formula area = length * breadth

SOURCE CODE:

package area;
import
java.util.Scann
er; public class
Area
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \n\t To Calculate the
Area of a Rectangle"); System.out.println("\
nGive the length of the rectangle");
int l=obj.nextInt();
System.out.println("\nGive the breadth of
the rectangle"); int b=obj.nextInt();
int a=l*b;
System.out.println(" \nArea = "+a);
}
}
OUTPUT:

To Calculate the Area of a


Rectangle Give the length of
the rectangle
5

Give the breadth of


the rectangle 4
Area = 20
PROGRAM :0
2
BIGGEST OF THREE NUMBERS

2. Write a java program to get three numbers and print the biggest one
among the three numbers.

AIM :To Find the biggest number from the given three numbers using if

statement and to print it.

SOURCE CODE:

package biggest;

import
java.util.Scanner;
public class Biggest
{
public static void main(String[] args)
{

Scanner obj=new Scanner(System.in);

System.out.println(" \n\t To Find the biggest number from the given 3


numbers"); System.out.println("\nGive the first number");
int a=obj.nextInt();
System.out.println("\nGive the
secondnumber"); intb=obj.nextInt();
System.out.println("\nGive the second number");
intc=obj.nextInt();

int max=a;
if ((b>max) &&(b>c)) max=b;
else if ((c>max) && (c>b)) max= c;
System.out.println(" Biggest number
="+max);
}

}
OUTPUT 1:
To Find the biggest number from the given 3
numbers Give the first number6
Give the second
number 8 Give the
second number 7
Biggest number =8
OUTPUT 2:
To Find the biggest number from the given 3
numbers Give the first number6
Give the second
number 7 Give the
second number 8
Biggest number =8
PROGRAM :
03
CATEGORY OF THE STUDENT
3. Write a java program to get the total marks scored by a student and print
the average and the category in which he/she comes.

AIM :To find the average and to categorize the position of the student in the
class using a multiple if statement.
PROGRAM CODE:
package category;
import
java.util.Scanner;
public class Category
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \n\t To Find the Category of the student");

System.out.println("\nGive the Total marks scored in 5 subjects");

int total=obj.nextInt();
float ave=total/5;
System.out.println("Your Average is "+ave); if (ave>85)
System.out.println("You are a OutstandingStudent");
else if(ave>=75)
System.out.println("You are in Distinction category");

else if(ave>=60)
System.out.println("You have passed with Firstclass"); else
if(ave>=40)
System.out.println("You have just passed");
else
System.out.println("Sorry .You have failed");
}
}
OUTPUT 1:
To Find the Category of the
student Give the Total marks
scored in 5 subjects 450
Your Average is 90.0
You are a Outstanding Student

OUTPUT 2:
To Find the Category of the
student Give the Total marks
scored in 5 subjects 175
Your Average is35.0
Sorry .You have
failed
PROGRAM : 04

VOWEL OR CONSONANT
4. Write a java program to input a character and check whether it is a vowel or
consonant and print it.

AIM :To Check whether a character is a vowel or consonant using if else statement.

SOURCE CODE:
package vowel;
import
java.util.Scanner;
public class Vowel
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \n\t To Check a character and print vowel or
consonant "); System.out.println("\nType any character");
char ch=obj.next().charAt(0);
if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||
ch=='u'||c h=='U')
System.out.println(ch +" is a
Vowel"); else
System.out.println(ch + “ is a Consonant”);
}
}
OUTPUT 1:
To Check a character and print vowel or
consonant Type any character
O
O is a Vowel
OUTPUT 2:
To Check a character and print vowel or
consonant Type any character
t
t is a Consonant

OUTPUT 3:
To Check a character and print vowel or
consonant Type any character a
a is a Vowel
PROGRAM : 05

NAME OF THE MONTH

5. Write a program to print the name of the month if the month number is given.

AIM:To print the name of the month if the month number is given using switch case
statement.

SOURCE CODE:

Package month;
import
java.util.Scanner;
public class Month
{
public static void main(String[] args)
{
Scanner obj=newScanner(System.in);
System.out.println(" \n\t To print the name of the month for given
number ");
System.out.println("\nType a
number"); int a=obj.nextInt();
switch (a)
{
case 1:
System.out.println("January
"); break;
case 2:
System.out.println("Februar
y"); break;
case 3:
System.out.println("March
"); break;
case 4:
System.out.println("April")
; break;
case 5:
System.out.println("May");
break;
case 6:
System.out.println("Jun
e"); break;
case 7:
System.out.println("July");
break;
case 8:
System.out.println("Augus
t"); break;
case 9:
System.out.println("Septemb
er"); break;
case 10:

System.out.println("October
"); break;
case 11:
System.out.println("Novemb
er"); break;
case 12:
System.out.println("Decemb
er"); break;
default:
System.out.println("Something is wrong..Enter the number from 1 to
12");
}
}
OUTPUT 1:

To print the name of the month for given

number Type a number


10

October

OUTPUT 2:

To print the name of the month for given

number Type a number


14

Something is wrong..Enter the number from 1 to 12


PROGRAM : 06

NUMBER SEQUENCE

Write a program to print all the numbers from 1 to 50 using for loop.

AIM: To print all the numbers from 1 to 50 using for loop.

SOURCE CODE:

package numbersequence;

public class Numbersequence


{
public static void main(String[] args)
{
System.out.println("\n\tTo print numbers from 1 to
50");

for(int i=1;i<=50;i++)
System.out.print(i+" ");

}
}
OUTPUT:
To print numbers from 1 to 50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2728
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
PROGRAM : 07

SQUARE OF EVEN NUMBERS

Write a java program to find and print square of all the even numbers from 1 to 10.

AIM :To find the square of all even numbers from 1 to 10 using while loop.

SOURCE CODE:
packagesquare;
import
java.util.Scanner;
public class Square
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \t To print the square of even
numbers"); System.out.println("Give the number up
to which you want the squares"); int n=obj.nextInt();
int i=2;
System.out.println(" Square of even numbers up to "+
n+" are"); while (i<=n)
{
System.out.println("Square of "+i+" =
"+i*i); i+=2;
}
}

}
OUTPUT :

To print the square of even


numbers Give the number up to
which you want the squares 10
Square of even numbers up to
10 are Square of 2 = 4
Square of 4 =16
Square of 6 =36
Square of 8 =64
Square of 10 = 100
PROGRAM : 08

MULTIPLES OF THREE
Write a program to display all the multiples of 3 from 1 to 100 using do..while loop

AIM: To display all the multiples of 3 from 1 to 100 using do..while loop.

SOURCE CODE:
Packagethreemultiples
; public class
ThreeMultiples
{
public static void main(String[] args)
{
int i=3;
System.out.println(" \t To print the multiples of three from 1 to
100");

do
{
System.out.print(i+"
"); i+=3;
}
while(i<100); System.out.println("Loop ended!");
}
}
OUTPUT:
To print the multiples of three from 1 to 100
3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75
78 81 84
87 90 93
96 99
Loop ended!
PROGRAM :
09
ARRAYS
9. Write a java program to input an array and to find the smallest and biggest
number in the array.

AIM :To input an array of integers and using array methods sort the array
and print the smallest and biggest number.

SOURCE CODE :
package smallest;
import
java.util.Scanner;
import
java.util.Arrays;
public class Smallest
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \t To Input an array");
System.out.println("Give the number of elements in the array\n");

int n=obj.nextInt(); int [] l=new int[n];


System.out.println("Enter the elements of the
array"); for (int i =0;i<n;i++)
{
System.out.print("Element of array
"+i+1+" - "); l[i]=obj.nextInt();
}
System.out.print("\nArrayValues
are "); for(inti=0;i<n;i++)
System.out.print(l[i]+" ,");
Arrays.sort(l);
System.out.print("\nSorted Array Values
are "); for(int i=0;i<n;i++)
System.out.print(l[i]+"
,"); int small = l[0];
int big=l[n-1];

System.out.println("\nSmallest number
="+small); System.out.println("\nBiggest
number ="+big);
}
}
OUTPUT :
To Input an array
Give the number of elements in the array 5
Enter the elements of the array Element of array
01 -90 Element of array 11 -23
Element of array 21 -56
Element of array 31 -78
Element of array 41 -900

Array Values are 90 ,23 ,56 ,78 ,900


Sorted Array Values are 23 ,56 ,78 ,90
,900 Smallest number=23
Biggest number=900
PROGRAM
10:
BINARY SEARCH
Write a java program to get an array and search an item in the array .

AIM :To input an array and search for an element in the array using Binary search
method.

SOURCE CODE:
Package search;

import
java.util.Scanner;
import java.util.Arrays;
public class Search

{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \t To Input an array");
System.out.println("Give the number of elements in the array\
n"); int n=obj.nextInt();
int [] l=new int[n];

System.out.println("Enter the elements of the array");

for (int i =0;i<n;i++) {


System.out.print("Element of array "+(i+1)+" - ");
l[i]=obj.nextInt(); }
System.out.println(" Give the number to be searched in the array");

int t=obj.nextInt();
System.out.print("\nArray Values are ");
for(int i=0;i<n;i++)
System.out.print(l[i]+"
,"); Arrays.sort(l);
System.out.print("\nSorted Array Values are ");
for(int i=0;i<n;i++)
System.out.print(l[i]+" ,");
int index =Arrays.binarySearch(l,t);
if (index>=0)
System.out.println("\nElement is found at "+ (index+1)+"
position"); else
System.out.println("\nElement not found in the list");
}

}
OUTPUT 1 :
To Input an array
Give the number of elements in the
array 5 Enter the elements of the
array
Element of array - 23
1
Element of array - 56
2
Element of array - 78
3
Element of array - 12
4
Element of array - 9
5
Give the number to be searched in the
array 1 Array Values are 23 ,56 ,78 ,12 ,9
Sorted Array Values are 9 ,12 ,23 ,56 ,78 Element not found in the list

OUTPUT 2 :
To Input an array
Give the number of elements in the
array 5 Enter the elements of the
array
Element of array - 12
1
Element of array - 78
2
Element of array - 45
3
Element of array - 90
4
Element of array - 34
5
Give the number to be searched in the
array 34 Array Values are 12 ,78 ,45
,90 ,34
Sorted Array Values are 12 ,34 ,45
,78 ,90 Element is found at 2
position
PROGRAM : 11

STRING MANIPULATION

Write a java program to manipulate the given string

AIM: To get a string and perform the basic string manipulation.

SOURCE CODE:
package str;
import
java.util.Scanner;
public class Str
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
System.out.println(" \n\t String Manipulation");
System.out.println("\nType any String without spaces in between");
String a=obj.next();
System.out.println(" String in Uppercase -"+a.toUpperCase());
System.out.println(" String in Lowercase -"+a.toLowerCase());
System.out.println(" Character at 5th location -"+a.charAt(5));
System.out.println(" Length of the given string -"+a.length());
System.out.println(" Replace all a by e -"+a.replace('a','e'));
System.out.println(" Cancatenation -"+a.concat("Namasthe. "));
System.out.println(" Does the string contain ram
-"+a.contains("ram"));
}
}
OUTPUT:

String Manipulation

Type any String without spaces in between


Ramakrishnar Does the string contain ram -false

Character at 5th location -r


Length of the given string -
12 Replace all a by e-
Remekrishner
String in Uppercase -
RAMAKRISHNAR String in
Lowercase -
ramakrishnarCancatenation -
RamakrishnarNamasthe.
PROGRAM :1
2
CLASS
Write a program to find the area and perimeter of a square using a class.

AIM :To calculate the area and perimeter of a square by using a class.

SOURCE CODE:

package squareclass;
import
java.util.Scanner;
class Square {
float side;
void area(float side) {
float ar=side*side; System.out.println("Area="+ar);
}
void peri(float side)

{ float pe=4*side;
System.out.println("Perimeter="+pe);
}

public class SquareClass {


public static void main(String[]
args)

{ Scanner obj=new
Scanner(System.in);
System.out.println(" \n\t To Calculate the Area & perimeter of a Square");
System.out.println("Give the side value");
float l=obj.nextFloat();
Square S= new
Square();
System.out.println("If side is
"+ l); S.area(l);
S.peri(l);
}

}
OUTPUT:
To Calculate the Area & perimeter of a
Square Give the side value
7
If side is 7.0 Area=49.0 Perimeter=28.0
PROGRAM : 13
CONSTRUCTOR

13. Write a java program to find the total and average of a student using
class with a constructors.

AIM :To calculate the total and average of a student using class with a
constructors.

SOURCE CODE:
package
studentcons; import
java.util.Scanner;
class Student{
int m1,m2,m3;
Student() {
m1=0;
m2=0
;
m3=0
;
}
int total() {
int
tot=m1+m2+m3;
return tot;
}
double average() {
double
avg=(m1+m2+m3)/3;
return avg;
}
}
public class StudentCons {
public static void main(String[] args)
{
Scanner obj=new

Scanner(System.in); Student s=

new Student();
System.out.println(“To find the total and average of a student”);
System.out.print("Enter English
mark="); s.m1=obj.nextInt();
System.out.print("Enter IT mark=");
s.m2=obj.nextInt();
System.out.print("Enter Accountancy
mark="); s.m3=obj.nextInt();
System.out.println("Total="+s.total());
System.out.println("Average="+s.averag
e());

}
}
OUTPUT:

To find the total and average of a


student Enter English mark=89
Enter IT mark=90
Enter
Accountancy
mark=92
Total=271
Average=90.0
PROGRAM :14

ASSERTION

Write a program to accept two numbers and print all the numbers between
them using appropriate assertion statement and rising exception message if
any.

AIM: To accept two numbers and print all the numbers between
them using appropriate assertion statement.

SOURCE CODE:
package
assertdemo; import
java.util.Scanner;
public class
AssertDemo
{
public static void main(String[] args)
{
Scanner obj=new
Scanner(System.in);
System.out.print("Enter the starting
no:"); int a=obj.nextInt();
System.out.print("Enter the ending
no:");
int b=obj.nextInt();
assert b>a:"Starting number is greater than the ending
number"; for(int i=a;i<=b;i++)
System.out.print(i+" ");

}
}
OUTPUT :1
Enter the starting
no:10 Enter the
ending no:5
Exception in thread "main" java.lang.AssertionError: Starting number is
greater than the ending number at
assertdemo.AssertDemo.main(AssertDemo.java:16) C:\Users\GKSVV\
AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53:
Java returned: 1

OUTPUT 2:
Enter the
starting no:
7 Enter the
ending no:
15

7 8 9 10 11 12 13 14 15
PROGRAM :15

EXCEPTION HANDLING
Write a java program to input 2 numbers and print the quotient if it is
divisible using exception handling.

AIM : To print the quotient if it is divisible otherwise print appropriate error


message using exception handling.
SOURCE CODE:
Package
exampleexception;
import
java.util.Scanner;
public class Exampleexception {
public static void main(String[]
args) { try
{
Scanner m =new Scanner(System.in);
System.out.println("Enter the first
number"); String f= m.next();
int a=Integer.parseInt(f);
Scanner n =new Scanner(System.in);
System.out.println("Enter the second
number"); String s= n.next();
int b=Integer.parseInt(s);
int p=a/b;
System.out.println("p="+p);
}
catch(Exception e) {
System.out.println(e.getMessag
e());
}
finally {
System.out.println("Safe Execution "); }
}

}
OUTPUT 1:
Enter the
first
number 8
Enter the
second
number 4
p=2
Safe Execution

OUTPUT 2:
Enter the
first
number 5
Enter the
second
number 0
/ by zero
Safe Execution

You might also like