SlideShare a Scribd company logo
2
Most read
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

DOC
Java programming lab assignments
rajni kaushal
 
DOCX
Java codes
Hussain Sherwani
 
DOCX
Java PRACTICAL file
RACHIT_GUPTA
 
DOC
Cs2312 OOPS LAB MANUAL
Prabhu D
 
PPT
Simple Java Programs
AravindSankaran
 
PDF
All experiment of java
Guru Janbheshver University, Hisar
 
PDF
Ds lab handouts
Ayesha Bhatti
 
Java programming lab assignments
rajni kaushal
 
Java codes
Hussain Sherwani
 
Java PRACTICAL file
RACHIT_GUPTA
 
Cs2312 OOPS LAB MANUAL
Prabhu D
 
Simple Java Programs
AravindSankaran
 
All experiment of java
Guru Janbheshver University, Hisar
 
Ds lab handouts
Ayesha Bhatti
 

What's hot (20)

DOC
CS2309 JAVA LAB MANUAL
Lavanya Arunachalam A
 
PDF
Technologies used in the PVS-Studio code analyzer for finding bugs and potent...
Andrey Karpov
 
PDF
Java lab-manual
Khurshid Asghar
 
PDF
Java Lab Manual
Naveen Sagayaselvaraj
 
PDF
66781291 java-lab-manual
Laura Popovici
 
DOCX
Java programming lab_manual_by_rohit_jaiswar
ROHIT JAISWAR
 
PDF
Java small steps - 2019
Christopher Akinlade
 
DOC
Procedure to create_the_calculator_application java
gthe
 
DOCX
Programs of java
shafiq sangi
 
PDF
Headache from using mathematical software
PVS-Studio
 
PPTX
Introduction to objective c
Mayank Jalotra
 
DOCX
Ecet 370 Education Organization -- snaptutorial.com
DavisMurphyB81
 
DOCX
java program assigment -2
Ankit Gupta
 
PDF
Java programming-examples
Mumbai Academisc
 
DOCX
ECET 370 Exceptional Education - snaptutorial.com
donaldzs157
 
DOCX
C# labprograms
Jafar Nesargi
 
ODP
Java Generics
Carol McDonald
 
PDF
Integration Project Inspection 3
Dillon Lee
 
PPT
Java 8 Streams
Manvendra Singh
 
CS2309 JAVA LAB MANUAL
Lavanya Arunachalam A
 
Technologies used in the PVS-Studio code analyzer for finding bugs and potent...
Andrey Karpov
 
Java lab-manual
Khurshid Asghar
 
Java Lab Manual
Naveen Sagayaselvaraj
 
66781291 java-lab-manual
Laura Popovici
 
Java programming lab_manual_by_rohit_jaiswar
ROHIT JAISWAR
 
Java small steps - 2019
Christopher Akinlade
 
Procedure to create_the_calculator_application java
gthe
 
Programs of java
shafiq sangi
 
Headache from using mathematical software
PVS-Studio
 
Introduction to objective c
Mayank Jalotra
 
Ecet 370 Education Organization -- snaptutorial.com
DavisMurphyB81
 
java program assigment -2
Ankit Gupta
 
Java programming-examples
Mumbai Academisc
 
ECET 370 Exceptional Education - snaptutorial.com
donaldzs157
 
C# labprograms
Jafar Nesargi
 
Java Generics
Carol McDonald
 
Integration Project Inspection 3
Dillon Lee
 
Java 8 Streams
Manvendra Singh
 
Ad

Viewers also liked (18)

DOCX
Mech nacp lab
Vivek Kumar Sinha
 
DOCX
Lab manual asp.net
Vivek Kumar Sinha
 
DOCX
Computer applications in civil engineering lab
Vivek Kumar Sinha
 
DOC
Cn lab manual
Vivek Kumar Sinha
 
PDF
Company Profile - Compressed
Solly Moeng - APR
 
PPTX
Teks ekposisi
BERBUDIANTO
 
PDF
Unit Testing on Android - Droidcon Berlin 2015
Buşra Deniz, CSM
 
DOCX
Oops lab manual
Vivek Kumar Sinha
 
DOC
Computer hardware and simulation lab manual
Vivek Kumar Sinha
 
DOC
Softwareenggineering lab manual
Vivek Kumar Sinha
 
DOCX
Graphics User Interface Lab Manual
Vivek Kumar Sinha
 
DOC
Dbms lab Manual
Vivek Kumar Sinha
 
DOC
Unix lab
Vivek Kumar Sinha
 
DOC
Network security Lab manual
Vivek Kumar Sinha
 
PDF
Eurest Breakfast White Paper
Gaurang Patel
 
PDF
WebRTC on Mobile
Buşra Deniz, CSM
 
DOCX
Graphics practical lab manual
Vivek Kumar Sinha
 
DOC
COMPUTER GRAPHICS LAB MANUAL
Vivek Kumar Sinha
 
Mech nacp lab
Vivek Kumar Sinha
 
Lab manual asp.net
Vivek Kumar Sinha
 
Computer applications in civil engineering lab
Vivek Kumar Sinha
 
Cn lab manual
Vivek Kumar Sinha
 
Company Profile - Compressed
Solly Moeng - APR
 
Teks ekposisi
BERBUDIANTO
 
Unit Testing on Android - Droidcon Berlin 2015
Buşra Deniz, CSM
 
Oops lab manual
Vivek Kumar Sinha
 
Computer hardware and simulation lab manual
Vivek Kumar Sinha
 
Softwareenggineering lab manual
Vivek Kumar Sinha
 
Graphics User Interface Lab Manual
Vivek Kumar Sinha
 
Dbms lab Manual
Vivek Kumar Sinha
 
Network security Lab manual
Vivek Kumar Sinha
 
Eurest Breakfast White Paper
Gaurang Patel
 
WebRTC on Mobile
Buşra Deniz, CSM
 
Graphics practical lab manual
Vivek Kumar Sinha
 
COMPUTER GRAPHICS LAB MANUAL
Vivek Kumar Sinha
 
Ad

Similar to Java final lab (20)

PPTX
Lab01.pptx
KimVeeL
 
PDF
Oot practical
Vipin Rawat @ daya
 
DOCX
Java Practice Set
Gaurav Dixit
 
DOCX
Java Practical1 based on Basic assignment
ashwinibhosale27
 
PDF
Lab exam question_paper
Kuntal Bhowmick
 
PDF
Sam wd programs
Soumya Behera
 
DOC
Practical java
nirmit
 
PPTX
Lab101.pptx
KimVeeL
 
DOCX
Important C program of Balagurusamy Book
Abir Hossain
 
PDF
Exercise1 java
NguynMinh294
 
PDF
Simple Java Program for beginner with easy method.pdf
ashwinibhosale27
 
DOC
Object oriented programming la bmanual jntu
Khurshid Asghar
 
PDF
Java programming lab manual
sameer farooq
 
PDF
Java practical N Scheme Diploma in Computer Engineering
mohamedarif0209
 
PDF
Simple 27 Java Program on basic java syntax
ashwinibhosale27
 
PDF
Java programlist (1)
Aditya Aggarwal
 
DOCX
Oop lab assignment 01
Drjilesh
 
DOCX
List of programs to practice for ICSE
Mokshya Priyadarshee
 
PDF
JavaProgrammingManual
Naveen Sagayaselvaraj
 
PPTX
Programs.pptx
kegeshaddy
 
Lab01.pptx
KimVeeL
 
Oot practical
Vipin Rawat @ daya
 
Java Practice Set
Gaurav Dixit
 
Java Practical1 based on Basic assignment
ashwinibhosale27
 
Lab exam question_paper
Kuntal Bhowmick
 
Sam wd programs
Soumya Behera
 
Practical java
nirmit
 
Lab101.pptx
KimVeeL
 
Important C program of Balagurusamy Book
Abir Hossain
 
Exercise1 java
NguynMinh294
 
Simple Java Program for beginner with easy method.pdf
ashwinibhosale27
 
Object oriented programming la bmanual jntu
Khurshid Asghar
 
Java programming lab manual
sameer farooq
 
Java practical N Scheme Diploma in Computer Engineering
mohamedarif0209
 
Simple 27 Java Program on basic java syntax
ashwinibhosale27
 
Java programlist (1)
Aditya Aggarwal
 
Oop lab assignment 01
Drjilesh
 
List of programs to practice for ICSE
Mokshya Priyadarshee
 
JavaProgrammingManual
Naveen Sagayaselvaraj
 
Programs.pptx
kegeshaddy
 

More from Vivek Kumar Sinha (20)

DOCX
Software engg unit 4
Vivek Kumar Sinha
 
DOCX
Software engg unit 3
Vivek Kumar Sinha
 
DOCX
Software engg unit 2
Vivek Kumar Sinha
 
DOCX
Software engg unit 1
Vivek Kumar Sinha
 
DOCX
Data structure
Vivek Kumar Sinha
 
PPTX
Mathematics basics
Vivek Kumar Sinha
 
PDF
E commerce 5_units_notes
Vivek Kumar Sinha
 
DOCX
Subject distribution
Vivek Kumar Sinha
 
DOCX
Revision report final
Vivek Kumar Sinha
 
DOC
Lession plan mis
Vivek Kumar Sinha
 
DOC
Lession plan dmw
Vivek Kumar Sinha
 
DOC
Faculty planning
Vivek Kumar Sinha
 
PPT
Final presentation on computer network
Vivek Kumar Sinha
 
DOCX
Np syllabus summary
Vivek Kumar Sinha
 
PPT
Internet of things
Vivek Kumar Sinha
 
PPT
Induction program 2017
Vivek Kumar Sinha
 
PDF
E magzine et&amp;t
Vivek Kumar Sinha
 
DOC
Mechanical engineering department (1)
Vivek Kumar Sinha
 
Software engg unit 4
Vivek Kumar Sinha
 
Software engg unit 3
Vivek Kumar Sinha
 
Software engg unit 2
Vivek Kumar Sinha
 
Software engg unit 1
Vivek Kumar Sinha
 
Data structure
Vivek Kumar Sinha
 
Mathematics basics
Vivek Kumar Sinha
 
E commerce 5_units_notes
Vivek Kumar Sinha
 
Subject distribution
Vivek Kumar Sinha
 
Revision report final
Vivek Kumar Sinha
 
Lession plan mis
Vivek Kumar Sinha
 
Lession plan dmw
Vivek Kumar Sinha
 
Faculty planning
Vivek Kumar Sinha
 
Final presentation on computer network
Vivek Kumar Sinha
 
Np syllabus summary
Vivek Kumar Sinha
 
Internet of things
Vivek Kumar Sinha
 
Induction program 2017
Vivek Kumar Sinha
 
E magzine et&amp;t
Vivek Kumar Sinha
 
Mechanical engineering department (1)
Vivek Kumar Sinha
 

Recently uploaded (20)

PDF
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
ijcncjournal019
 
PPTX
Chapter----five---Resource Recovery.pptx
078bce110prashant
 
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
Ajaykumar966781
 
PDF
Queuing formulas to evaluate throughputs and servers
gptshubham
 
PDF
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
PDF
Introduction to Data Science: data science process
ShivarkarSandip
 
PPTX
Azure-DevOps-Training presentation downloadable
NamanGoyal428595
 
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
quakeplayz54
 
PDF
Traditional Exams vs Continuous Assessment in Boarding Schools.pdf
The Asian School
 
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
ghousebhasha2007
 
PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PPT
High Data Link Control Protocol in Data Link Layer
shailajacse
 
PPTX
Production of bioplastic from fruit peels.pptx
alwingeorgealwingeor
 
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Dr. Rahul Kumar
 
PDF
Principles of Food Science and Nutritions
Dr. Yogesh Kumar Kosariya
 
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
dodultrongaming
 
PDF
Structs to JSON How Go Powers REST APIs.pdf
Emily Achieng
 
PPT
Ppt for engineering students application on field effect
lakshmi.ec
 
PPTX
Ship’s Structural Components.pptx 7.7 Mb
abdalwhab7327
 
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
ijcncjournal019
 
Chapter----five---Resource Recovery.pptx
078bce110prashant
 
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
Ajaykumar966781
 
Queuing formulas to evaluate throughputs and servers
gptshubham
 
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
Introduction to Data Science: data science process
ShivarkarSandip
 
Azure-DevOps-Training presentation downloadable
NamanGoyal428595
 
Lesson 3_Tessellation.pptx finite Mathematics
quakeplayz54
 
Traditional Exams vs Continuous Assessment in Boarding Schools.pdf
The Asian School
 
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
ghousebhasha2007
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
High Data Link Control Protocol in Data Link Layer
shailajacse
 
Production of bioplastic from fruit peels.pptx
alwingeorgealwingeor
 
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Dr. Rahul Kumar
 
Principles of Food Science and Nutritions
Dr. Yogesh Kumar Kosariya
 
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
dodultrongaming
 
Structs to JSON How Go Powers REST APIs.pdf
Emily Achieng
 
Ppt for engineering students application on field effect
lakshmi.ec
 
Ship’s Structural Components.pptx 7.7 Mb
abdalwhab7327
 

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