Kripal Java File
Kripal Java File
Kripal Java File
S.
No. Date Aim of the Experiment Signature/Date Grade
1 Write a Program to find Area of the Circle
double r1;
r1= r*(3.14);
System.out.println("Area of Circle is " +r );
}
}
Output
Experiment No : 2
Title: Write a program to find sum and reverse of three digit number.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
public class p2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("\n Enter the Number you want to reverse --- ");
int r = sc.nextInt();
int s=0,n;
int rev=0;
while(r>0)
{
n=r%10;
s=s+n;
rev=rev*10+n;
r=r/10;
}
System.out.println("sum of digits " + s);
System.out.println("reverse of digits " + rev);
}
}
Output
Experiment No : 3
Title : Write a program to swap two numbers without using third
variable.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO1
Source code:
import java.util.*;
public class p3 {
public static void main(String[] args) {
int a=10,b=5;
System.out.println("\n The two Integers are a = " +a+ " and b = " +b);
a=a+b;
b=a-b;
a=a-b;
System.out.println("After Swapping a = " +a+ " and b = " +b);
}
}
Output
Experiment No: 4
Title : Write a program to find simple interest.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO1
Source code:
import java.util.*;
public class p4 {
public static void main(String[] args) {
int pa,r,t;
Scanner sc = new Scanner(System.in);
}
Output
Experiment No: 5
Title : Write a program to find List of Prime Numbers.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
import java.util.*;
lim = sc.nextInt();
count = 0;
if (num % divisor == 0) {
count++;
break;
}
}
System.out.println(num);
}
}
Output
Experiment No: 6
Title : Write a program to find sequence of n numbers which are
divisible by 3 and 5 both.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
import java.util.*;
public class p5 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n = sc.nextInt();
}
num++;
}
}
}
Output
Experiment No: 7
Title : Write a program to find the Roots of a Quadratic Equation.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO1
Source code:
import java.util.*;
class p12{
double a = scanner.nextDouble();
double b = scanner.nextDouble();
double c = scanner.nextDouble();
double discriminant = b * b - 4 * a * c;
double[] roots;
if (discriminant > 0) {
} else if (discriminant == 0) {
double root = -b / (2 * a);
} else {
System.out.println("No real roots");
return;
if (roots.length == 2) {
} else {
}
}
Output
Experiment No: 8
Title : Write a program to find the factorial of n Number.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
import java.util.*;
public class p6 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = sc.nextInt();
int fact = 1;
for (int i = 1; i <= n; i++) {
fact *= i;
}
}
Output
Experiment No: 9
Title : Write a program to find the sequence of Fibonacci series up to
n terms.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
import java.util.Scanner;
public class p7 {
public static void main(String[] args) {
int sum,a=0,b=1,num;
{
sum = a + b;
System.out.println("\n"+sum);
a=b;
b=sum;
}
}
}
Output
Experiment No: 10
Title : Write a program to check whether given number is palindrome
or not.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
import java.util.*;
public class p8 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
if(org==rev)System.out.println("It is palindrome");
else
System.out.println("Not Palindrome");
}
}
Output
Experiment No: 11
Title : Write a program to find HCF of two numbers.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
import java.util.*;
class p9{
int n1,n2,hcf;
n1= sc.nextInt();
n2= sc.nextInt();
hcf=i;
break;
}
}
}
Output
Experiment No: 12
Title : Write a Java Program that will display the sum of
1+1/2+1/3…..+1/n.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
import java.util.*;
int n;
double sum = 0;
n = sc.nextInt();
for (int i = 1; i <= n; i++) {
}
Output
Experiment No: 13
Title : Write a Java Program that will print the following outputs:
1
22
333
4444
55555
4444
333
22
1
Source code:
public class y1 {
System.out.print(i);
}
System.out.println();
System.out.print(i);
}
System.out.println();
Output
Title : Write a Java Program that will print the following outputs:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Source code:
class y1 {
public static void main(String[] args) {
System.out.print(" ");
}
System.out.println();
}
Output
Title : Write a Java Program that will print the following outputs:
$
$$
$$$
$$$$
$$$$$
Source code:
class y1 {
System.out.print("$");
}
System.out.println();
Output
Experiment No: 14
Source code:
class y1 {
int r2 = 3, c2 = 3;
}
}
System.out.println("Product of matrices:");
}
System.out.println();
Output
Experiment No: 15
Title : Write a Java Program to find sum and subtraction of two
matrices.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
import java.util.Scanner;
class y1 {
c1 = sc.nextInt();
r2 = sc.nextInt();
c2 = sc.nextInt();
if (r1 != r2 || c1 != c2) {
System.out.println("Matrices must have the same dimensions for
addition and subtraction.");
return;
matrix1[i][j] = sc.nextInt();
matrix2[i][j] = sc.nextInt();
System.out.println();
}
System.out.println("Subtraction of the matrices:");
System.out.println();
}
sc.close();
Output
Experiment No: 16
Title : Write a Java Program to sort the list in ascending Order.
Source code:
import java.util.*;
class y1 {
arr[i] = scanner.nextInt();
}
Arrays.sort(arr);
Output
Experiment No: 17
Title : Write a Java Program to convert decimal into binary number.
class y1 {
decimal = decimal / 2;
Output
Experiment No: 18
Title : Write a Java Program to find largest and smallest of n numbers.
Source code:
import java.util.Scanner;
class y1 {
int n;
n = scanner.nextInt();
numbers[i] = scanner.nextInt();
largest = numbers[i];
smallest = numbers[i];
Output
Experiment No: 19
Title : Write a java program which shows the application of
constructors.
y1() {
num = 10;
y1(int value) {
num = value;
}
Output
Experiment No: 20
Title : Write a java program to find the electricity bill using
inheritance. The details are as follow.
Source code:
import java.util.Scanner;
class ElectricityBill {
int units;
ElectricityBill(int units) {
this.units = units;
double calculateBill() {
return units * 2;
} else if (units <= 300) {
} else {
public class y1 {
Output
Experiment No: 21
Title : Write a java program to find the result sheet of a student
using Interfaces. The details are as follow:
Marks Grade
>90 Excellent
>60 and <=90 Good
Below 60 Average
Source code:
import java.util.Scanner;
interface Result {
void calculateResult();
System.out.println("Grade: Excellent");
System.out.println("Grade: Good");
} else {
System.out.println("Grade: Average");
}
public class y1 {
student.subject1 = scanner.nextInt();
student.subject2 = scanner.nextInt();
student.calculateResult();
Output
Experiment No: 22
Title : Write a java program which shows importing of classes from
other packages.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
// Dell.java
package laptop;
// Hp.java
package laptop;
public class Hp {
public static String model = "Pavilion";
import laptop.Dell;
import laptop.Hp;
public class y1 {
public static void main(String[] args) {
}
}
Output
Experiment No: 23
Title : Write a java program which creates threads using the thread
class.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
class y1 extends Thread {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
thread1.start();
thread2.start();
}
Output
Experiment No: 24
Title : Write a java program which use try and catch for exception
handling.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
public class y1 {
int denominator = 0;
} catch (ArithmeticException e) {
System.out.println("Error: Division by zero is not allowed.");
Output
Experiment No: 25
Title : Write a java program which use multiple catch blocks.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
public class y1 {
public static void main(String[] args) {
try {
} catch (ArithmeticException e) {
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("ArrayIndexOutOfBoundsException: " +
e.getMessage());
} catch (Exception e) {
Output
Experiment No: 26
Title : Write a java program which shows throwing our own
exception.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
import java.util.Scanner;
class y1 {
} else {
try {
validateAge(userAge);
} catch (CustomException e) {
}
}
super(message);
}
Output
Experiment No: 27
Title : Write a program to handle Labels and Buttons using AWT
Controls.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
import java.awt.*;
import java.awt.event.*;
public class y1 {
public static void main(String[] args) {
Frame frame = new Frame("Sample program by yKD");
Label label = new Label("Hello, YKD!");
Button button = new Button("Click here Boss");
frame.setLayout(new FlowLayout());
frame.add(label);
frame.add(button);
frame.setSize(300, 150);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
}
}
Output
Experiment No: 28
Title : Write a program to handle Check Boxes using AWT Controls
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
import java.awt.*;
import java.awt.event.*;
public class y1 {
public static void main(String[] args) {
Frame frame = new Frame("Checkbox Example");
frame.setLayout(new FlowLayout());
frame.add(new Label("Select Gender:"));
frame.add(maleCheckbox);
frame.add(femaleCheckbox);
frame.setSize(300, 150);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
}
}
Output
Experiment No: 29
Title : Write a program to handle Lists and Scroll Bars using AWT
Controls.
Objective : Revision of Programming Techniques using Java.
Pre-requisted:
Knowledge of OOPs Concepts
Eclipse Code
Targeted CO:CO2
Source code:
import java.awt.*;
import java.awt.event.*;
class y1 {
y1() {
Frame f = new Frame("List and ScrollBar Example");
f.add(l);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
Output