SlideShare a Scribd company logo
1 of 8
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
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
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
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
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
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
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
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

More Related Content

What's hot

66781291 java-lab-manual
66781291 java-lab-manual66781291 java-lab-manual
66781291 java-lab-manual
Laura Popovici
ย 
Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application java
gthe
ย 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
Mayank Jalotra
ย 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
Mumbai Academisc
ย 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
Jafar Nesargi
ย 
Java Generics
Java GenericsJava Generics
Java Generics
Carol McDonald
ย 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
Dillon Lee
ย 

What's hot (20)

CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
ย 
Technologies used in the PVS-Studio code analyzer for finding bugs and potent...
Technologies used in the PVS-Studio code analyzer for finding bugs and potent...Technologies used in the PVS-Studio code analyzer for finding bugs and potent...
Technologies used in the PVS-Studio code analyzer for finding bugs and potent...
ย 
Java lab-manual
Java lab-manualJava lab-manual
Java lab-manual
ย 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
ย 
66781291 java-lab-manual
66781291 java-lab-manual66781291 java-lab-manual
66781291 java-lab-manual
ย 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswar
ย 
Java small steps - 2019
Java   small steps - 2019Java   small steps - 2019
Java small steps - 2019
ย 
Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application java
ย 
Programs of java
Programs of javaPrograms of java
Programs of java
ย 
Ch4
Ch4Ch4
Ch4
ย 
Headache from using mathematical software
Headache from using mathematical softwareHeadache from using mathematical software
Headache from using mathematical software
ย 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
ย 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.com
ย 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
ย 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
ย 
ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com
ย 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
ย 
Java Generics
Java GenericsJava Generics
Java Generics
ย 
Integration Project Inspection 3
Integration Project Inspection 3Integration Project Inspection 3
Integration Project Inspection 3
ย 
Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
ย 

Viewers also liked

Company Profile - Compressed
Company Profile - CompressedCompany Profile - Compressed
Company Profile - Compressed
Solly Moeng - APR
ย 

Viewers also liked (18)

Mech nacp lab
Mech nacp labMech nacp lab
Mech nacp lab
ย 
Lab manual asp.net
Lab manual asp.netLab manual asp.net
Lab manual asp.net
ย 
Computer applications in civil engineering lab
Computer applications in civil engineering labComputer applications in civil engineering lab
Computer applications in civil engineering lab
ย 
Cn lab manual
Cn lab manualCn lab manual
Cn lab manual
ย 
Company Profile - Compressed
Company Profile - CompressedCompany Profile - Compressed
Company Profile - Compressed
ย 
Teks ekposisi
Teks ekposisiTeks ekposisi
Teks ekposisi
ย 
Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015
ย 
Oops lab manual
Oops lab manualOops lab manual
Oops lab manual
ย 
Computer hardware and simulation lab manual
Computer  hardware and simulation lab manualComputer  hardware and simulation lab manual
Computer hardware and simulation lab manual
ย 
Softwareenggineering lab manual
Softwareenggineering lab manualSoftwareenggineering lab manual
Softwareenggineering lab manual
ย 
Graphics User Interface Lab Manual
Graphics User Interface Lab ManualGraphics User Interface Lab Manual
Graphics User Interface Lab Manual
ย 
Dbms lab Manual
Dbms lab ManualDbms lab Manual
Dbms lab Manual
ย 
Unix lab
Unix labUnix lab
Unix lab
ย 
Network security Lab manual
Network security Lab manual Network security Lab manual
Network security Lab manual
ย 
Eurest Breakfast White Paper
Eurest Breakfast White PaperEurest Breakfast White Paper
Eurest Breakfast White Paper
ย 
WebRTC on Mobile
WebRTC on MobileWebRTC on Mobile
WebRTC on Mobile
ย 
Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manual
ย 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
ย 

Similar to Java final lab

Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
KimVeeL
ย 
4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf
amitbhachne
ย 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
AbhishekSingh757567
ย 
Object oriented programming la bmanual jntu
Object oriented programming la bmanual jntuObject oriented programming la bmanual jntu
Object oriented programming la bmanual jntu
Khurshid Asghar
ย 

Similar to Java final lab (20)

Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
ย 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diploma
ย 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
ย 
Lab101.pptx
Lab101.pptxLab101.pptx
Lab101.pptx
ย 
4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf
ย 
Java Question-Bank-Class-8.pdf
Java Question-Bank-Class-8.pdfJava Question-Bank-Class-8.pdf
Java Question-Bank-Class-8.pdf
ย 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
ย 
programming for Calculator in java
programming for Calculator in javaprogramming for Calculator in java
programming for Calculator in java
ย 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
ย 
JavaProgrammingManual
JavaProgrammingManualJavaProgrammingManual
JavaProgrammingManual
ย 
Net practicals lab mannual
Net practicals lab mannualNet practicals lab mannual
Net practicals lab mannual
ย 
Introduction to Java Programming Part 2
Introduction to Java Programming Part 2Introduction to Java Programming Part 2
Introduction to Java Programming Part 2
ย 
java program assigment -1
java program assigment -1java program assigment -1
java program assigment -1
ย 
Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2
ย 
Java programs
Java programsJava programs
Java programs
ย 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
ย 
3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf3.Lesson Plan - Input.pdf.pdf
3.Lesson Plan - Input.pdf.pdf
ย 
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
ย 
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.pdf
ย 
Object oriented programming la bmanual jntu
Object oriented programming la bmanual jntuObject oriented programming la bmanual jntu
Object oriented programming la bmanual jntu
ย 

More from Vivek Kumar Sinha

More from Vivek Kumar Sinha (20)

Software engg unit 4
Software engg unit 4 Software engg unit 4
Software engg unit 4
ย 
Software engg unit 3
Software engg unit 3 Software engg unit 3
Software engg unit 3
ย 
Software engg unit 2
Software engg unit 2 Software engg unit 2
Software engg unit 2
ย 
Software engg unit 1
Software engg unit 1 Software engg unit 1
Software engg unit 1
ย 
Data structure
Data structureData structure
Data structure
ย 
Mathematics basics
Mathematics basicsMathematics basics
Mathematics basics
ย 
E commerce 5_units_notes
E commerce 5_units_notesE commerce 5_units_notes
E commerce 5_units_notes
ย 
B.ped
B.pedB.ped
B.ped
ย 
Subject distribution
Subject distributionSubject distribution
Subject distribution
ย 
Revision report final
Revision report finalRevision report final
Revision report final
ย 
Lession plan mis
Lession plan misLession plan mis
Lession plan mis
ย 
Lession plan dmw
Lession plan dmwLession plan dmw
Lession plan dmw
ย 
Faculty planning
Faculty planningFaculty planning
Faculty planning
ย 
Final presentation on computer network
Final presentation on computer networkFinal presentation on computer network
Final presentation on computer network
ย 
Np syllabus summary
Np syllabus summaryNp syllabus summary
Np syllabus summary
ย 
Internet of things
Internet of thingsInternet of things
Internet of things
ย 
Induction program 2017
Induction program 2017Induction program 2017
Induction program 2017
ย 
Vivek
VivekVivek
Vivek
ย 
E magzine et&amp;t
E magzine et&amp;tE magzine et&amp;t
E magzine et&amp;t
ย 
Mechanical engineering department (1)
Mechanical engineering department (1)Mechanical engineering department (1)
Mechanical engineering department (1)
ย 

Recently uploaded

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
ย 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
ย 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
ย 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
ย 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
rknatarajan
ย 

Recently uploaded (20)

AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ย 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
ย 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
ย 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
ย 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
ย 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
ย 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
ย 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
ย 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
ย 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
ย 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
ย 
Top Rated Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
ย 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
ย 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ย 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
ย 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
ย 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
ย 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
ย 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
ย 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
ย 

Java final lab

  • 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