IES University, Bhopal
PRACTICAL FILE
Name of Student : ABHIJEET KUMAR
Enrollment No : 1IES22CSE006
Subject : Programming in Java
Subject code : DCS - 515
Course : Diploma
Branch : CSE
Semester : 5TH
Session : August 2024 – December 2024
Department of Computer Science & Engineering
INDEX
S. NO. EXPERIMENT NAME EXPERIMENT SUBMISSION SIGN &
DATE DATE REMARK
1 WAP to print your name in Java ?
2 WAP to print sum of two numbers ?
3 WAP to print area of circle ?
4 WAP to check given number is Even or
Odd ?
5 WAP to find greater number between two
number ?
6 WAP to check the person is eligible for
voting or not ?
7 WAP to print table of a given number ?
8 WAP to print factorial of a given number ?
9 WAP to print Fedonacci Series ?
10 WAP to print sum of two array by using
class ?
EXPERIMENT : 01 AIM
: WAP to print your name in Java ?
class name {
public static void main(String[] args) {
System.out.println("Mohammad kaif khan");
}
}
OUTPUT:-
Mohammad kaif khan
=== Code Execution Successful ===
EXPERIMENT : 02 AIM
: WAP to print sum of two numbers ?
class
add {
public static void main(String[] args)
{
System.out.println("sum of two numbers");
int sum = 45+55;
System.out.println(sum);
}
}
OUTPUT:- sum of two
numbers
100
=== Code Execution Successful ===
EXPERIMENT : 03 AIM
: WAP to print area of circle ?
import java.util.Scanner; public
class AreaOfCircle { public static void
main(String args[]){ int radius;
double area;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the radius of the circle ::");
radius = sc.nextInt(); area = (radius*radius)*Math.PI;
System.out.println("Area of the circle is ::"+area);
}
}
OUTPUT:-
Enter the radius of the circle ::
5
Area of the circle is ::78.53981633974483
=== Code Execution Successful ===
AIM : WAP
EXPERIMENT : 04
to check given number is even or odd ?
import java.util.Scanner; public class
EvenOdd { public static void
main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = reader.nextInt(); if(num % 2
== 0)
System.out.println(num + " is even");
else
System.out.println(num + " is odd");
}
}
OUTPUT:-
Enter a number: 24
24 is even
AIM : WAP
=== Code Execution Successful ===
EXPERIMENT : 05
to find greater number between two number ?
import java.util.Scanner; public
class Main {
public static void main(String[] args) {
int num1 = 50, num2 =20; if(num1==
num2)
System.out.println("both are equal"); else if (num1>num2)
System.out.println (num1 + " is greater"); else
System.out.println(num2 + " is greater ");
}
}
OUTPUT:-
50 is greater
=== Code Execution Successful ===
AIM : WAP
EXPERIMENT : 06
to check the person is eligible for voting or not ?
import java.util.Scanner; public class Voting
{ public static void main(String[] args) { int age ;
Scanner scan = new Scanner(System.in);
System.out.println("Please enter your age: ");
age = scan.nextInt(); if(age>=18 && age<=100) {
System.out.println("You are eligible for voting.");
}
else {
System.out.println("Sorry,You can not vote ");
}
}}
OUTPUT:-
Please enter your age:
99
You are eligible for voting.
=== Code Execution Successful ===
AIM : WAP
EXPERIMENT : 07
AIM : WAP to print table of a given number ?
import java.util.Scanner; public class
Table { public static void
main(String[ ] args) { Scanner in =
new Scanner(System.in);
System.out.print("Input a number: ");
int num1 = in.nextInt();
for (int i= 0; i< 10; i++)
{
System.out.println(num1 + " x " + (i+ 1) + " = " + (num1 * (i+ 1)));
}
}}
OUTPUT:-
Input a number: 12
12 x 1 = 12
12 x 2 = 24
12 x 3 = 36
12 x 4 = 48
12 x 5 = 60
12 x 6 = 72
12 x 7 = 84
12 x 8 = 96
12 x 9 = 108
12 x 10 = 120
=== Code Execution Successful ===
EXPERIMENT : 08 AIM
: WAP to factorial of a given number ?
import java.util.Scanner; public
class Main {
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number: ");
int num=sc.nextInt(); int i=1,fact=1;
while(i<=num) { fact=fact*i;
i++; }
System.out.println("Factorial of the number: "+fact);
}
}
OUTPUT:-
Enter the number:
4
Factorial of the number: 24
=== Code Execution Successful ===
EXPERIMENT : 09
AIM : WAP to Fedonacci Series ?
class Main {
public static void main(String[] args) { int
n = 10, firstTerm = 0, secondTerm = 1;
System.out.println("Fibonacci Series till " + n + " terms:"); for
(int i = 1; i <= n; ++i) {
System.out.print(firstTerm + ", "); int
nextTerm = firstTerm + secondTerm;
firstTerm = secondTerm;
secondTerm = nextTerm;
}}}
OUTPUT:-
Fibonacci Series till 10 terms:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,
=== Code Execution Successful ===
EXPERIMENT : 10
AIM : WAP to print sum of two array by using class ?
import java.util.*; public
class Main {
public static void main(String[] args) {
int[] a = {51, 16, 33, 2, 14, 21}; int[] b
= {33, 9, 56, 21, 39, 21}; int[] c = new
int[a.length]; if(a.length==b.length) {
for (int i = 0 ,j=0,k=0; i < a.length; i++,j++,k++){ c[k]
= a[i] + b[j];
}
System.out.println("Resultant array is:");
System.out.println(Arrays.toString(c));
} else {
System.out.println("Length of both array should be same");
}}}
OUTPUT:-
Resultant array is:
[84, 25, 89, 23, 53, 42]
=== Code Execution Successful ===