0% found this document useful (0 votes)
139 views28 pages

IT Practical 2024 - 2025

IT

Uploaded by

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

IT Practical 2024 - 2025

IT

Uploaded by

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

XII : Practical Information Technology (802)

SSCE Practical (2024 – 2025)

Experiment : 01

Program 1 : Write a Java program to enter your name and print.

Solution :

import java.util.Scanner;
public class MyClass {
public static void main(String arg[ ])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter your Name : ");
String s = sc.next();
System.out.println("Your Name is : " + s);
}
}

Output

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 1 of 28
XII : Practical Information Technology (802)

Experiment : 02

Program 2 : Write a Java program to input any two integer values. Add both
values and print the result.

Solution :

import java.util.Scanner;
public class MyClass {
public static void main(String arg[ ])
{
Scanner sc = new Scanner(System.in);
int n1, n2, r;
System.out.println("Enter First Number : ");
n1 = sc.nextInt();
System.out.println("Enter Second Number : ");
n2 = sc.nextInt();
r = n1 + n2;
System.out.println("Sum = "+ r);
}
}

Output

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 2 of 28
XII : Practical Information Technology (802)

Experiment : 03

Program 3 : Write a Java program to input a two digits number. Print reverse
of given number.

Solution :

import java.util.Scanner;

public class MyClass {


public static void main(String arg[ ])
{
int n, d1, d2, r;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Two Digits Number : ");
n = sc.nextInt();
d1 = n / 10;
d2 = n % 10;
r = d2*10 + d1;
System.out.println("Reverse of " + n + " is " + r);
}
}

Output

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 3 of 28
XII : Practical Information Technology (802)

Experiment : 04

Program 4 : Write a Java program to input a number. Check whether it is


even or odd.

Solution :

import java.util.Scanner;

public class MyClass {


public static void main(String arg[ ])
{
int n;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Number : ");
n = sc.nextInt();
if(n%2 == 0)
System.out.println(n + " is even no.");
else
System.out.println(n + " is odd no.");
}
}

Output

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 4 of 28
XII : Practical Information Technology (802)

Experiment : 05

Program 5 : Write a Java program to input a three digits number. Check


whether it is Palindrome or not.

Solution :

import java.util.Scanner;

public class MyClass {


public static void main(String arg[ ])
{
int n, d1, d2, d3, r;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Three Digits Number : ");
n = sc.nextInt();
d1 = n / 100;
d2 = n / 10 % 10;
d3 = n % 10;
r = d3 * 100 + d2 * 10 + d1;
if(n == r)
System.out.println(n + " is Palinderome");
else
System.out.println(n + " is Not Palindrome");
}
}

Output

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 5 of 28
XII : Practical Information Technology (802)

Experiment : 06
Program 6 : Write a Java program to input values between 1 & 7 and display
the name of respective weekday.
Solution :
import java.util.Scanner;
public class MyClass {
public static void main(String arg[ ]) {
int ch;
Scanner sc = new Scanner(System.in);
System.out.print("Enter Number ( 1 - 7) : ");
ch = sc.nextInt();
switch (ch) {
case 1:
System.out.println("Sunday");
break;
case 2:
System.out.println("Monday");
break;
case 3:
System.out.println("Tuesday");
break;
case 4:
System.out.println("Wednesday"); Output 1
break;
case 5:
System.out.println("Thursday");
break;
case 6:
System.out.println("Friday");
break;
case 7:
System.out.println("Saturday");
break;
default :
System.out.println("Wrong Input !"); Output 2
}
}
}

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 6 of 28
XII : Practical Information Technology (802)

Experiment : 07

Program 7 : Write a Java program to input a number. Print table of given


number.

Solution :

import java.util.Scanner;
public class MyClass {
public static void main(String arg[ ]) {
int n, i;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Number : ");
n = sc.nextInt();
for(i =1; i<=10; i=i+1)
System.out.println(n + " X " + i + " = " + n * i);
}
}

Output

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 7 of 28
XII : Practical Information Technology (802)

Experiment : 08

Program 08 : Write a Java program to enter a number of any digits. Count


number of digits and print.

Solution :

import java.util.Scanner;

public class MyClass {


public static void main(String arg[ ]) {
int n, c = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Number of any Digits : ");
n = sc.nextInt();
while(n!=0)
{
c = c + 1;
n = n / 10;
}
System.out.println("Total Number of Digits = " + c);
}
}

Output

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 8 of 28
XII : Practical Information Technology (802)

Experiment : 09

Program 09 : Write a Java program to store any 10 values in an array. Add


all values and print the result.

Solution :

import java.util.Scanner;
public class MyClass {
public static void main(String arg[ ]) {
int[ ] a = new int[10];
int i, s = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter any ten values : ");
for(i = 0; i<10; i++)
{
a[i] = sc.nextInt();
s = s + a[i];
}
System.out.println("Sum = " + s);
}
}

Output

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 9 of 28
XII : Practical Information Technology (802)

Experiment : 10

Program 10 : Write a Java program to store any 5 names in an array. Sort in


ascending order and print.

Solution :

import java.util.*;
public class MyClass {
public static void main(String arg[ ]) {
String[ ] sname = new String[5];
int i;
Scanner sc = new Scanner(System.in);
System.out.print("Enter any five names : ");
for(i = 0; i<5; i++)
{
sname[i] = sc.next();
}
Arrays.sort(sname);
System.out.println("All Names in Ascending order are : ");
for(i=0; i<sname.length; i++)
System.out.println(sname[i]);
}
}

Output

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 10 of 28
XII : Practical Information Technology (802)

Experiment : 11

Program 11 : Write a Java program to create a constructor for initialize


name, roll and class of a student and print it.

Solution :

public class MyClass {


public static void main(String arg[ ]) {
demo d = new demo();
d.display();
}
}
class demo
{
String name;
int roll, clas;
demo()
{
name = "Rajesh Kumar";
roll = 1;
clas = 12;
}
void display( )
{
System.out.println("Name : " + name);
System.out.println("Roll : " + roll);
System.out.println("Class : " + clas);
}
}

Output

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 11 of 28
XII : Practical Information Technology (802)

Experiment : 12
Program 12 : Write a Java program to use string methods.

Solution :

import java.util.Arrays;
public class MyClass {
public static void main(String arg[ ]) {
String s = "Programming Language ";
System.out.println(s.charAt(5));
System.out.println(s.concat("Java"));
System.out.println(s.contains("Language"));
System.out.println(s.endsWith("age "));
System.out.println(s.equals("Programming Language "));
System.out.println(s.equalsIgnoreCase("programming language "));
System.out.println(s.indexOf("L"));
System.out.println(s.isEmpty());
System.out.println(s.length());
System.out.println(s.replace("Programming", "Java"));
System.out.println(s.replaceAll("Programming", "J"));
System.out.println(s.startsWith("Pro"));
System.out.println(s.substring(3, 7));
System.out.println(s.toLowerCase());
System.out.println(s.toUpperCase());
System.out.println(s.trim());
}
}

Output

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 12 of 28
XII : Practical Information Technology (802)

Experiment : 13
Program 13 : Write a Java program to create thread by extending Thread
class.

Solution :

public class MyClass{


public static void main(String arg[ ]) {
myThread mt1 = new myThread();
mt1.start();
myThread mt2 = new myThread();
mt2.start();
}
}
class myThread extends Thread
{
public void run()
{
System.out.println("It is my Thread");
}
}

Output

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 13 of 28
XII : Practical Information Technology (802)

Experiment : 14
Program 14 : Write a Java program to input your name and display it in
another textfield.

Solution :

private void btnDispalyActionPerformed(java.awt.event.ActionEvent evt)


{
String s;
s = T1.getText();
T2.setText(s);
}

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 14 of 28
XII : Practical Information Technology (802)

Experiment : 15

Program 15 : Write a Java program to input any two integer values. Add both
value and display the result.

Solution :

private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {

int n1 = Integer.parseInt(jTextField1.getText());
int n2 = Integer.parseInt(jTextField2.getText());
jTextField3.setText(n1 + n2 + " ");
}

private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {

jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");

private void btnExitActionPerformed(java.awt.event.ActionEvent evt)

{
System.exit(0);
}

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 15 of 28
XII : Practical Information Technology (802)

Experiment : 16

Program 16 : Write a Java program to input a three digits number and


display reverse of given number.

Solution :

private void btnReverseNoActionPerformed(java.awt.event.ActionEvent evt)

int n, d1,d2,d3,r;
n = Integer.parseInt(txtNo.getText());
d1 = n / 100;
d2 = n / 10 % 10;
d3 = n % 10;
r = d3 * 100 + d2 * 10 + d1;
txtResult.setText("Reverse Number is " + r);

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 16 of 28
XII : Practical Information Technology (802)

Experiment : 17

Program 17 : Write a Java program to input cost price and selling prince of
an item. Calculate profit or loss and display result.

Solution :

private void btnProfitLossActionPerformed(java.awt.event.ActionEvent evt) {

int cp, sp;


cp = Integer.parseInt(txtCP.getText());
sp = Integer.parseInt(txtSP.getText());
if(cp > sp)
txtResult.setText("Loss = " + (cp - sp));
else
txtResult.setText("Profit = " + (sp - cp))
}

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 17 of 28
XII : Practical Information Technology (802)

Experiment : 18
Program 18 : Write a Java program to input a three digits number. Check
whether it is Armstrong number or not.

Solution :

private void btnArmstrongNoActionPerformed(java.awt.event.ActionEvent evt)


{

int n, d1, d2, d3, a;


n = Integer.parseInt(txtNo.getText());
d1 = n / 100;
d2 = n / 10 % 10;
d3 = n % 10;
a = d1 * d1 * d1 + d2 * d2 * d2 + d3 * d3 * d3;
if (a == n)
txtResult.setText(n + " is Armstrong Number");
else
txtResult.setText(n + " is not Armstrong Number");
}

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 18 of 28
XII : Practical Information Technology (802)

Experiment : 19
Program 19 : Write a Java program to input a three digits number. Check
whether it is Palindrome number or not.

Solution :

private void btnPalindromeNoActionPerformed(java.awt.event.ActionEvent


evt)

{
int n, d1, d2, d3, a;
n = Integer.parseInt(txtNo.getText());
d1 = n / 100;
d2 = n / 10 % 10;
d3 = n % 10;
a = d1 * 100 + d2 * 10 + d3;
if (a == n)
txtResult.setText(n + " is Palindrome Number");
else
txtResult.setText(n + " is not Palindrome Number")
}

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 19 of 28
XII : Practical Information Technology (802)

Experiment : 20
Program 20 : Write a Java program to input a number. Calculate sum from 1
to given number and display result in another window.

Solution :

import javax.swing.JOptionPane;

private void btnSumActionPerformed(java.awt.event.ActionEvent evt) {

int n, i, s=0;
n = Integer.parseInt(txtNo.getText());
for(i = 1; i <= n; i = i + 1)
s = s + i;
JOptionPane.showMessageDialog(rootPane,"Sum = " + s);
}

private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {

txtNo.setText("");
txtNo.grabFocus();
}

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 20 of 28
XII : Practical Information Technology (802)

Experiment : 21
Program 21 : Write a Java program to select course(s) from multiple courses
and display result.

Solution :

private void btnCourseActionPerformed(java.awt.event.ActionEvent evt) {

String s= "";
if(CB1.isSelected())
s = s + CB1.getText();
else
s = s + "";
if(CB2.isSelected())
s = s + CB2.getText();
else
s = s + "";
if(CB3.isSelected())
s = s + CB3.getText();
else
s = s + "";
if(CB4.isSelected())
s = s + CB4.getText();
else
s = s + "";
txtResult.setText("You have Selected : " + s);
}

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 21 of 28
XII : Practical Information Technology (802)

Experiment : 22
Program 22 : Write a Java program to change background color of JFrame
by selecting color name from multiple color choices.

Solution :

private void RB1ActionPerformed(java.awt.event.ActionEvent evt) {

if(RB1.isSelected())
getContentPane().setBackground(Color.red);
}

private void RB2ActionPerformed(java.awt.event.ActionEvent evt) {

if(RB2.isSelected())
getContentPane().setBackground(Color.blue);
}

private void RB3ActionPerformed(java.awt.event.ActionEvent evt) {

if(RB3.isSelected())
getContentPane().setBackground(Color.green);
}

private void RB4ActionPerformed(java.awt.event.ActionEvent evt) {

if(RB4.isSelected())
getContentPane().setBackground(Color.yellow);
}

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 22 of 28
XII : Practical Information Technology (802)

Experiment : 23
Program 23 : Write a Java program to add text from jTextField to jList.

Solution :

import javax.swing.DefaultListModel;

private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {

DefaultListModel d = new DefaultListModel();


d.addElement(txtItem.getText());
txtItem.setText("");
jList1.setModel(d);
}

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 23 of 28
XII : Practical Information Technology (802)

Experiment : 24

Program 24 : Write a Java program to add “One, Two, Three, Four, Five” as
items in jComboBox by clicking jButton. Display items of jComboBox in
jTextField by selecting items in jComboBox.

Solution :

private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {

jComboBox1.addItem("One");
jComboBox1.addItem("Two");
jComboBox1.addItem("Three");
jComboBox1.addItem("Four");
jComboBox1.addItem("Five");
}

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {

txtResult.setText(jComboBox1.getSelectedItem().toString());
}

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 24 of 28
XII : Practical Information Technology (802)

Experiment : 25
Program 25 : Design an application for login page In Java.
Solution :

import javax.swing.JOptionPane;
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}

private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {

if(txtUser.getText( ).equals("Kumar"))
{
if(txtPassword.getText().equals("Admin"))
{
JOptionPane.showMessageDialog(rootPane, "Welcome !");
txtUser.setText("");
txtPassword.setText("");
}
else
{
JOptionPane.showMessageDialog(rootPane,"Wron Password
!");
txtPassword.setText("");
}
}
else
{
JOptionPane.showMessageDialog(rootPane,"Wron User Name !");
txtUser.setText("");
}
}

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 25 of 28
XII : Practical Information Technology (802)

Experiment : 26
AIM : Write SQL command to create a Student table with student id, name
and marks fields where student id is primary key.

Solution :

Create table student


(
Student_id varchar(10) primary key,
Name varchar(30),
Marks int
);

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 26 of 28
XII : Practical Information Technology (802)

Experiment : 27
AIM : Write SQL command to insert records of any five students in Student
table.

Solution :

Insert into Student values(‘101’, ‘Palak’, 90);


Insert into Student values(‘102’, ‘Khushi’, 92);
Insert into Student values(‘103’, ‘Ayushi’, 95);
Insert into Student values(‘104’, ‘Sumit’, 90);
Insert into Student values(‘105’, ‘Himanshu’, 90);

Experiment : 28
AIM : Write SQL command to delete a particular record of a student in
Student table.

Solution :

Delete from Student where Student_id = “105”;


Select * from Student;

Experiment : 29
AIM : Write SQL command to display records of those students who have
marks greater than 70 in Student table.

Solution :

Select * from Student where marks > 70;

Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 27 of 28
XII : Practical Information Technology (802)

Experiment : 30
AIM : Write SQL command to find min, max, sum and average of the marks
in Student table.

Solution :

Select min(marks), max(marks), sum(marks), average(marks) from Student;

Experiment : 31
AIM : Consider the following tables :
Order

Customer

Write SQL commands for the following :


(i) To create a foreign key in above table.
(ii) To find the total number of customers from each country in the
above table.
(iii) To display customer names in descending order.
(iv) To display customername, orderdate of India;
Solution :
(i) Alter table Order add foreign key (customerid ) references Customer
(customerid);
(ii) Select country, count(*) “Total Customer” from customer group by
country;
(iii) Select customername from customer order by customername desc;
(iv) Select customer.customername, order.orderdate from Customer,
Order where customer.country = “India”;
Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 28 of 28

You might also like