IT Practical 2024 - 2025
IT Practical 2024 - 2025
Experiment : 01
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;
Output
Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 3 of 28
XII : Practical Information Technology (802)
Experiment : 04
Solution :
import java.util.Scanner;
Output
Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 4 of 28
XII : Practical Information Technology (802)
Experiment : 05
Solution :
import java.util.Scanner;
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
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
Solution :
import java.util.Scanner;
Output
Kumar Gourab (DAV PS, CRRC, Medical Road, Gaya Email : [email protected]) Page 8 of 28
XII : Practical Information Technology (802)
Experiment : 09
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
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
Solution :
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 :
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 :
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 :
int n1 = Integer.parseInt(jTextField1.getText());
int n2 = Integer.parseInt(jTextField2.getText());
jTextField3.setText(n1 + n2 + " ");
}
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
{
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
Solution :
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 :
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 :
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 :
{
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;
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);
}
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 :
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 :
if(RB1.isSelected())
getContentPane().setBackground(Color.red);
}
if(RB2.isSelected())
getContentPane().setBackground(Color.blue);
}
if(RB3.isSelected())
getContentPane().setBackground(Color.green);
}
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;
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 :
jComboBox1.addItem("One");
jComboBox1.addItem("Two");
jComboBox1.addItem("Three");
jComboBox1.addItem("Four");
jComboBox1.addItem("Five");
}
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);
}
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 :
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 :
Experiment : 28
AIM : Write SQL command to delete a particular record of a student in
Student table.
Solution :
Experiment : 29
AIM : Write SQL command to display records of those students who have
marks greater than 70 in Student table.
Solution :
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 :
Experiment : 31
AIM : Consider the following tables :
Order
Customer