It Practical File 2023 24
It Practical File 2023 24
TECHNOLOGY
PROGRAM~FILE
[2023-24]
2. Input by User 4
3. Decide if or else 7
4. Switch Case 11
5. While Statement 13
7. Arrays 17
9. Class 21
10. String Manipulation 22
11. Exception Handling 24
TEACHER’S SIGNATURE
Operators
Q1. Find the Surface Area/ Volume of a cone of radius 5 units and
height 12 units.
INPUT:
double r= 5;
double h= 12;
double LSq = (r*r)+(h*h);
double l= Math.pow(LSq,0.5 );
System.out.println("THE CURVED SURFACE AREA OF CONE IS :
"+(3.14*r*l)+" SQ. Units");
System.out.println("THE TOTAL SURFACE AREA OF CONE IS :
"+((3.14*r*l)+(3.14*r*r))+" SQ. Units");
System.out.println("THE Volume OF CONE IS : "+(0.3333*3.14*r*r*h)+"
Cubic Units");
}
OUTPUT:
Q2. Find the Area and Perimeter of a rectangle and determine whether
it is a square or not.
INPUT:
double l= 7, b= 7;
double perimeter= 2*(l+b);
double area = l*b;
System.out.println("THE PERIMETER OF RECTANGLE IS:
"+perimeter);
System.out.println("THE area OF RECTANGLE IS: "+area);
double a= Math.pow(area, 0.5);
if(a==l || a==b){
System.out.println("IT IS A SQUARE");
}
else{
System.out.println("IT IS A RECTANGLE"); } }
OUTPUT:
Q3. Perform Basic Mathematical Operations for two numbers.
INPUT:
int a= 60;
int b=30;
System.out.println("THE ADDITION OF NUMBERS IS : "+(a+b));
System.out.println("THE SUBTRACTION OF NUMBERS IS : "+(a-b));
System.out.println("THE MULTIPLICATION OF NUMBERS IS : "+(a*b));
System.out.println("THE DIVISION OF NUMBERS IS : "+(a/b));
OUTPUT:
Input by User
Q1. Take the Input for principal amount, time period and interest rate,
and calculate the compound interest.
INPUT:
package programfile;
import java.util.*;
public class INPUT_user {
public static void main(String[] args) {
Scanner pt = new Scanner(System.in);
double b = 1+ 0.01*r;
double x = Math.pow(b, t);
double CI =(p*x)-p;
System.out.println("THE COMPOUND INTEREST IS : "+CI);
OUTPUT:
Q2. Take the Input for temperature in Celsius and convert it to Kelvin
and Fahrenheit.
INPUT:
package programfile;
import java.util.*;
public class INPUT2 {
public static void main(String[] args) {
Scanner pt= new Scanner(System.in);
System.out.println("ENTER THE TEMPERATURE IN CELSIUS :");
float c= pt.nextFloat();
float f = (c*9/5)+32;
float k = c+ 273;
System.out.println("THE TEMPERATURE IN FAHRENHIET IS :"+f);
System.out.println("THE TEMPERATURE IN KELVIN IS :"+k);
}
OUTPUT:
Decide IF or Else
Q1. Write a program to decide whether the entered year is a leap year
or not.
INPUT:
package programfile;
import java.util.*;
public class if_else1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("ENTER A YEAR : ");
int y =input.nextInt();
if(y%400==0){
System.out.println("IT IS A LEAP YEAR");}
else if(y%100==0){
System.out.println("IT IS NOT A LEAP YEAR");}
else if(y%4==0){
if(p>=75){
System.out.println("DISTINCTION : I");
System.out.println("YOU HAVE PASSED CLASS 12");
System.out.println("YOU ARE QUALIFIED FOR JEE main");}
else if(p>=65 && p<75){
System.out.println("DISTINCTION : II");
System.out.println("YOU HAVE PASSED CLASS 12 ");
System.out.println("YOU ARE NOT QUALIFIED FOR JEE main");}
else if(p>=33 && p<65){
System.out.println("DISTINCTION : III");
System.out.println("YOU HAVE PASSED CLASS 12 ");
System.out.println(" YOU ARE NOT QUALIFIED FOR JEE main");}
else if( p<33){
System.out.println("DISTINCTION : FAIL");
System.out.println(" YOU HAVE FAILED CLASS 12");
System.out.println("BETTER LUCK NEXT TIME ");}
OUTPUT:
Switch Case
Q1. Write a program to give details of different shoe brands(price
ranges, size ranges) depending on brand code.
INPUT:
Scanner input = new Scanner(System.in);
System.out.println("P:Puma M:MAHESH N:Nike ");
System.out.println("ENTER SHOE BRAND NAME: ");
char pt= input.next().charAt(0);
switch(pt){
case 'p': System.out.println("PRICE RANGE --> Rs 4000-50000 \n
AVAILABLE SIZE :- 2,3,4,7,9"); break;
case 'm': System.out.println("PRICE RANGE --> Rs 20-99999 \n
AVAILABLE SIZE :- 2,3,4,6,8,7,9,10,11,12"); break;
case 's': System.out.println("PRICE RANGE --> Rs 8999-120000 \n
AVAILABLE SIZE :- 3,4,8,7,9,12"); break;
default : System.out.println("INVALID INPUT");
OUTPUT:
Q2. Write a program to determine whether entered character is a vowel
or a consonant.
INPUT:
Scanner input =new Scanner(System.in);
System.out.println("ENTER AN ALPHABET :");
char pt = input.next().charAt(0);
switch (pt){
case 'a' : case 'A' : case 'I' : case 'i' : case 'U' : case 'u' : case 'e' :
case 'E' : case 'o' : case 'O' :
System.out.println("IT IS A VOWEL.");
break;
default: System.out.println("IT IS A CONSONANT.");
OUTPUT:
While Statement
Q1. Write a program to print the squares of all the numbers lesser than the
entered number.
INPUT:
package programfile;
import java.util.*;
public class while01 {
public static void main(String[] args) {
Scanner pt =new Scanner(System.in); int a=1;
System.out.println("ENTER A NUMBER :");
int num = pt.nextInt();
while(a<num){
int SQ= a*a;
System.out.println("SQUARE OF "+a+" IS :"+SQ); a++;
Q2. Write a program to find sum of the squares of all numbers till the
entered number.
INPUT:
package programfile;
import java.util.*;
public class while_00002 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a=1 ,sum =0;
System.out.println("Enter A number Of Your Choice");
int n= input.nextInt();
while(a<=n){
sum = sum+(a*a); a++;}
System.out.println("THE SUM OF ALL SQUARES UP TILL "+n+" IS "+sum);
OUTPUT:
FOR Loop Statement
Q1. Write a program to display the multiplication table up to 10 for any
entered number.
INPUT:
package programfile;
import java.util.*; public
class for_01 {
public static void main(String[] args) {
Scanner pt =new Scanner(System.in);
System.out.print("ENTER YOUR FAVOURITE NUMBER: ");
int p= pt.nextInt(); for(int i=1;i<=10;i++){
System.out.println(p+" * "+i+" = "+(p*i) );
}
Q2. Write a program to display all the factors of any entered number.
INPUT:
import java.util.*; public
class for_02 {
public static void main(String[] args) {
Scanner pt= new Scanner(System.in);
System.out.print("ENTER THE NUMBER YOU WANT :");
int b= pt.nextInt();
System.out.println("FACTORS OF "+b+" are :");
for(int i=1;i<=b;i++){ if(b%i==0){
System.out.println(i);
OUTPUT:
ARRAYS
Q1. Create an Array of integers and write a program to display the
largest and the smallest numbers in the array.
INPUT:
import java.util.*; public
class Arrayyys1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] marks= {6,54,90,68,-45,94,44}; int l
=marks[0]; int s =marks[0];
for(int i=0;i<marks.length;i++){
if(marks[i]>l){ l=marks[i];}
if(marks[i]<s){ s=marks[i]; }}
System.out.println("Largest number is "+l);
System.out.println("SMALLEST number is "+s);
Q2. Create a string array and write a program to display all the elements in
the array.
INPUT:
package programfile; public
class Array02 {
public static void main(String[] args) {
String a[]={"Honey Singh","Arijit Singh","Vishal Dadlani","Udit
Narayan","Armaan Malik","A. R. Rahaman"};
for(int i=0;i<a.length;i++)
{
System.out.println(a[i]);
}
USER DEFINED METHOD
Q1. Write a program to create a method to calculate cube root of
numbers.
INPUT: package
programfile; import
java.util.*;
public class usewrdefinedmethod1 { static
double cubeRoot(double m){ double b =
Math.pow(3,-1); return(Math.pow(m, b));
}
public static void main(String[] args) { Scanner
input = new Scanner(System.in); double a =
cubeRoot(27);
System.out.println(a);
Q2. Write a program to create a method to calculate basic trigonometric
ratios.
INPUT:
package programfile; import
java.util.*; public class method2 {
static double sine(double a){
return(Math.sin(a));} static
double cosine(double a){
return(Math.cos(a));} static
double tan(double a){
return(Math.tan(a));}
publicstaticvoidmain(String[]args
Scanner input = new Scanner(System.in);
System.out.print("Enter : "); double n= );
CLASS
Q1. Write a program to create a class to display the Book Name, Author
and price, respectively for any certain book.
INPUT:
package programfile;
class Book{ String bookname;
String author;
double price;
Book(String b, String a, double p)
{ bookname=b; author=a; price=p;} void display()
{ System.out.println("Book name: "+bookname);
System.out.println("Author: "+author);
System.out.println("Price: "+price);}}
public class class1 { public static void main(String[] args)
{ Book book1= new Book("ALice in Wonderland","John keats",420.69);
book1.display();
String Manipulation
Q1. Consider the string str=”Global Warming” .
Write Statements to implement the following:
a) To display the last 4 characters.
b) To change the case of the given string.
c) To display the length of the string.
d) To check if the string contains the substring “Wa”.
e) To replace all occurrences of the letter ‘a’ in the string by ‘*’.
INPUT:
public class strng { public static void main(String[] args)
{ Scanner input = new Scanner(System.in);
String str="Global Warming";
int a = str.length()-4;
for(int i=a; i<str.length(); i++){
System.out.println(str.charAt(i)); }
System.out.println();
System.out.println(str.toUpperCase());
System.out.println(str.toLowerCase());
System.out.println(str.length());
System.out.println(str.contains("Wa"));
System.out.println(str.replace('a','*'));
OUTPUT:
Exception Handling
Q1. Write a program depicting the scenario where an arithmetic
exception occurs.
INPUT:
package programfile;
import java.util.*;
public class excptn {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
The CREATE DATABASE statement is a DDL (Data Definition Language) statement used to
create a new database in SQL.
Syntax
Following is the syntax to create a database in SQL –
- CREATE DATABASE DatabaseName;
In an SQL server, the database is a collection of tables, views, stored procedures, and other
objects that are used to store and manage data.
Syntax
Following is the syntax to show databases in SQL –
- SHOW DATABASES;
STRUCTURE OF TABLE
DESCRIBE means to show the information in detail. Since we have tables in MySQL, so we will
use the DESCRIBE command to show the structure of our table, such as column names,
constraints on column names, etc. The DESC command is a short form of the DESCRIBE
command. Both DESCRIBE and DESC command are equivalent and case sensitive.
Syntax
The following are the syntax to display the table structure-
Let us understand it with the help of an example that explains how to show columns of the
table in the selected database.
INSERTING AND DISPLAYING
RECORDS
The SQL INSERT INTO Statement is used to add new rows of data to a table in the
database.
The INSERT statement will only accept the data that follows all the attributes of a
column in a table. The data inserted into a table must have same datatypes, satisfy the
constraints (if any), etc. If the inserted data does not satisfy any of the attributes, the
INSERT INTO statement displays an error.
Syntax
The basic syntax of the INSERT INTO statement which is shown below.
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)
VALUES (value1, value2, value3,...valueN);
To retrieve the data from the database, we can use the SELECT statement in SQL, which is
used to retrieve data from one or more tables.
Syntax
Following is the syntax of displaying records of a table in SQL-
The NOT NULL constraint in SQL is used to ensure that a column in a table doesn't
contain NULL (empty) values, and prevent any attempts to insert or update rows with
NULL values.
Usually, if we don't provide value to a particular column while inserting data into a table,
by default, it is considered as a NULL value. But, if we add the NOT NULL constraint on
a column. While inserting data we must provide value of the respective column else the
operation will fail and an error message will be displayed.
Syntax
The following is the basic syntax of NOT NULL while creating a table −
CREATE TABLE table_name (
column1 datatype NOT NULL,
column2 datatype,
column3 datatype NOT NULL,
...
);
SELECT DISTINCT
The SELECT DISTINCT statement is used to return only distinct (different) values.
Inside a table, a column often contains many duplicate values; and sometimes you only
want to list the different (distinct) values.
Syntax
SELECT DISTINCT column1, column2, ...
FROM table_name;
WHERE CLAUSE
WHERE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition;
LIKE OPERATOR
The LIKE operator is used in a WHERE clause to search for a specified pattern in a
column.
There are two wildcards often used in conjunction with the LIKE operator:
The percent sign and the underscore can also be used in combinations!
Syntax
SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
DELETING RECORDS
Syntax
DELETE FROM table_name WHERE condition;
Note: Be careful when deleting records in a table! Notice the WHERE clause in
the DELETE statement. The WHERE clause specifies which record(s) should be deleted. If
you omit the WHERE clause, all records in the table will be deleted!
UPDATING TABLE
The UPDATE statement is used to modify the existing records in a table.
Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Note: Be careful when updating records in a table! Notice the WHERE clause in
the UPDATE statement. The WHERE clause specifies which record(s) that should be
updated. If you omit the WHERE clause, all records in the table will be updated!
BETWEEN OPERATOR
The BETWEEN operator selects values within a given range. The values can be
numbers, text, or dates.
The BETWEEN operator is inclusive: begin and end values are included.
Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
GROUP BY STATEMENT
The GROUP BY statement groups rows that have the same values into summary rows, like
"find the number of customers in each country".
Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
HAVING CLAUSE
The HAVING clause was added to SQL because the WHERE keyword cannot be used
with aggregate functions.
Syntax
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);