1. Shri Rawatpura Sarkar Institute of Technology,New Raipur
Department of Computer Science & Enggineering
List of Experiment to be performed
1. Write a program to check whether a number is an Armstrong number or not.
2. Write a program to sort a stream of Strings.
3. Write a program to perform multiplication of two matrices.
4. Write a program to find the volume of a box having its side w, h, d means width, height and depth.
Its volume is
v=w*h*d and also find the surface area given by the formula s=2(wh+hd+dw), use appropriate
constructors for the
above.
5. Develop a program to illustrate a copy constructor so that a string may be duplicated into another
variable either by
assignment or copying.
6. Create a base class called shape. It contains two methods getxyvalue() and showxyvalue() for
accepting co-ordinates
and to display the same. Create the subclass called Rectangle which contains a method to display the
length and
breadth of the rectangle called showxyvalue().Use overriding concept.
7. Write a program that creates an abstract class called dimension, creates two subclasses, rectangle
and triangle. Include
appropriate methods for both the subclass that calculate and display the area of the rectangle and
triangle.
8. Write a program which throws Arithmetic Exception. Note the output; write another class (in a
different file) that
handles the Exception.
9. Create a user defined Exception class which throws Exception when the user inputs the marks
greater than 100.
10. Write a program in which a Mythread class is created by extending the Thread class. In another
class, create objects of
the Mythread class and run them. In the run method print โCSVTUโ 10 times. Identify each thread by
setting the name.
11. Write a program using InetAddress class and also show the utility of URL and URL Connection
classes.
12. Write a program which illustrates capturing of Mouse Events. Use Applet class for this.
13. Write a program using RMI in which a simple remote method is implemented.
14. Write a servlet program using HttpServlet class. Also give the appropriate HTML file which posts
data to the servlet.
15. Write a JDBC program for Student Mark List Processing.
16. Design a text editor which is having some of the features of notepad.
Program 1: Swapping using temporary or third variable
import java.util.Scanner;
class SwapNumbers{
public static void main(String args[])
{
int x, y, temp;
System.out.println("Enter x and y");
Scanner in = new Scanner(System.in);
CSE/5th
/JAVA Lab/Prepared by Vivek Kumar Sinha
2. Shri Rawatpura Sarkar Institute of Technology,New Raipur
Department of Computer Science & Enggineering
x = in.nextInt();
y = in.nextInt();
System.out.println("Before Swappingnx = "+x+"ny = "+y);
temp = x;
x = y;
y = temp;
System.out.println("After Swappingnx = "+x+"ny = "+y);
}
}
Program 2: Swapping without temporary variable
import java.util.Scanner;
class SwapNumbers{
public static void main(String args[])
{
int x, y;
System.out.println("Enter x and y");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
System.out.println("Before Swappingnx = "+x+"ny = "+y);
x = x + y;
y = x - y;
x = x - y;
System.out.println("After Swappingnx = "+x+"ny = "+y);
CSE/5th
/JAVA Lab/Prepared by Vivek Kumar Sinha
3. Shri Rawatpura Sarkar Institute of Technology,New Raipur
Department of Computer Science & Enggineering
}
}
Program 3
This java program prints multiplication table of a number entered by the user using a
for loop.
Java source code
import java.util.Scanner;
class MultiplicationTable
{
public static void main(String args[])
{
int n, c;
System.out.println("Enter an integer to print it's multiplication table");
Scanner in = new Scanner(System.in);
n = in.nextInt();
System.out.println("Multiplication table of "+n+" is :-");
for ( c = 1 ; c <= 10 ; c++ )
System.out.println(n+"*"+c+" = "+(n*c));
}
}
Program 4 :/*Armstrong Number*/
import java.io.*;
class armstrong{
public static void main(String [] args) throws IOException{
try {
BufferedReader obc=new BufferedReader (new InputStreamReader(System.in));
int n1,r,n2,arm=0;
System.out.println("Please enter the number: ");
n1=Integer.parseInt(obc.readLine());
CSE/5th
/JAVA Lab/Prepared by Vivek Kumar Sinha
4. Shri Rawatpura Sarkar Institute of Technology,New Raipur
Department of Computer Science & Enggineering
n2=n1;
while(n1>0) {
r=n1%10;
arm=arm+r*r*r;
n1=n1/10;
}
if(n2==arm) {
System.out.println("The no. is Armstrong.");
}
else {
System.out.println("The no. is not Armstrong.");
}
}catch(IOException e) {
System.out.println("The entered no. is wrong");
}
}
}
Program 4:
Sum of Two Numbers
class sum
{
public static void main(String args[])
{
int a,b;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
System.out.print("The Sum of numbers is " +(a+b));
}
}
CSE/5th
/JAVA Lab/Prepared by Vivek Kumar Sinha
5. Shri Rawatpura Sarkar Institute of Technology,New Raipur
Department of Computer Science & Enggineering
Program 5: Pallindrome
class pal
{
public static void main(String args[])
{
int a,i,j,b=0;
String s1,s2;
s1=args[0];
char tar[]=s1.toCharArray();
a=s1.length();
for(i=0,j=a-1;i<a/2;i++,j--)
{
if(tar[i]!=tar[j])
b=1;
}
if(b==1)
System.out.print("It is a not a palindrome");
else
System.out.print("It is a palindrome");
}
}
Program 6: Reversing a String
class rev
{
public static void main(String args[])
{
int a;
a=Integer.parseInt(args[0]);
System.out.print("The reversed number is ");
while(a>0)
{
System.out.print(a%10);
a=a/10;
}
}
}
Program 7: java program to find largest of three numbers
This java program finds largest of three numbers and then prints it. If the entered
numbers are unequal then "numbers are not distinct" is printed.
import java.util.Scanner;
class LargestOfThreeNumbers
{
public static void main(String args[])
CSE/5th
/JAVA Lab/Prepared by Vivek Kumar Sinha
6. Shri Rawatpura Sarkar Institute of Technology,New Raipur
Department of Computer Science & Enggineering
{
int x, y, z;
System.out.println("Enter three integers ");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
z = in.nextInt();
if ( x > y && x > z )
System.out.println("First number is largest.");
else if ( y > x && y > z )
System.out.println("Second number is largest.");
else if ( z > x && z > y )
System.out.println("Third number is largest.");
else
System.out.println("Entered numbers are not distinct.");
}
}
Program 8: java program print prime numbers
This java program prints prime numbers, number of prime numbers required is asked
from the user. Remember that smallest prime number is 2.
Java programming code
import java.util.*;
class PrimeNumbers
{
public static void main(String args[])
{
int n, status = 1, num = 3;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of prime numbers you want ");
n = in.nextInt();
if ( n >= 1 )
{
System.out.println("First "+n+" prime numbers are :-");
System.out.println(2);
}
for ( int count = 2 ; count <=n ; )
{
for ( int j = 2 ; j <= Math.sqrt(num) ; j++ )
{
if ( num%j == 0 )
CSE/5th
/JAVA Lab/Prepared by Vivek Kumar Sinha
7. Shri Rawatpura Sarkar Institute of Technology,New Raipur
Department of Computer Science & Enggineering
{
status = 0;
break;
}
}
if ( status != 0 )
{
System.out.println(num);
count++;
}
status = 1;
num++;
}
}
}
Program 9: java program to print Floyd's triangle
import java.util.Scanner
class FloydTriangle
{
public static void main(String args[])
{
int n, num = 1, c, d;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows of floyd's triangle you want");
n = in.nextInt();
System.out.println("Floyd's triangle :-");
for ( c = 1 ; c <= n ; c++ )
{
for ( d = 1 ; d <= c ; d++ )
{
System.out.print(num+" ");
num++;
}
System.out.println();
}
}
}
Program 10: java program to reverse a string
import java.util.*;
class ReverseString
{
public static void main(String args[])
{
CSE/5th
/JAVA Lab/Prepared by Vivek Kumar Sinha
8. Shri Rawatpura Sarkar Institute of Technology,New Raipur
Department of Computer Science & Enggineering
String original, reverse ="";
Scanner in = new Scanner(System.in);
System.out.println("Enter a string to reverse");
original = in.nextLine();
int length = original.length();
for ( int i = length - 1 ; i >= 0 ; i-- )
reverse = reverse + original.charAt(i);
System.out.println("Reverse of entered string is "+reverse);
}
}
CSE/5th
/JAVA Lab/Prepared by Vivek Kumar Sinha