Professional Documents
Culture Documents
Lab Practical-1
Lab Practical-1
Lab Practical-1
AIM:
To write a java program to perform the arithmetic operations for the given numbers.
SOURCE CODE:
int b,c;
int x=25;
int y=10;
int z=x+y;
int a=x-y;
b=x*y;
c=x/y;
OUTPUT:
x+y = 35
x-y = 15
x*y = 250
x/y = 2
RESULT:
SOURCE CODE:
int x=25;
int y=100;
if(x>y)
else
OUTPUT:
RESULT:
AIM:
To write a java program to perform the find the given number is odd or even.
SOURCE CODE:
int x=25;
if(x%2==0)
else
OUTPUT:
RESULT:
Thus the given number is found as odd or even and it is displayed successfully.
AIM:
double si,ci,p,n,r;
p=50000;
n=2;
r=5;
si=(p*n*r)/100;
OUTPUT:
RESULT:
AIM:
To write a java program to find the given number is positive, negative or zero..
SOURCE CODE:
class Number{
int n=-20;
if (n>0)
else if(n<0)
else
OUTPUT:
RESULT:
Thus the given number is found positive, negative or zero and displayed successfully.
AIM:
To write a java program to calculate the factorial value for the given number.
SOURCE CODE:
class HelloWorld {
public static void main(String[] args) {
while(n>0)
fact=fact*i;
n=n-1;
OUTPUT:
RESULT:
Thus the factorial value for the given number is calculated and displayed.
AIM:
SOURCE CODE:
class Swap {
b=a+b;
a=b-a;
System.out.println("Value in a:"+a);
System.out.println("Value in b:"+b);
OUTPUT:
Value in a:30
Value in b:40
RESULT:
AIM:
SOURCE CODE:
class Sum {
int i, sum=0;
for (i=1;i<=10;i++)
sum=sum+i;
OUTPUT:
RESULT:
AIM:
SOURCE CODE:
class Array {
a[0]=10;
a[1]=20;
a[2]=70;
a[3]=40;
a[4]=50;
for(int i=0;i<a.length;i++)
System.out.println(a[i]);
OUTPUT:
Values are: 10
20
70
40
50
RESULT:
AIM:
To write a java program to find the given year is a leap year or not.
SOURCE CODE:
class Leap {
int year=2022;
if(year%4==0)
else
System.out.println(year+" is not a Leap Year");
class year{
y.display();
OUTPUT:
RESULT:
Thus the given year is found whether leap year or not and displayed successfully.
PARAMETERIZED CONSTRUCTOR
AIM:
SOURCE CODE:
class Constructor {
int a, b;
Constructor(int x, int y)
{
a=x;
b=y;
System.out.println("Parameterized Constructor");
}
public void display(){
System.out.println("Value of a: "+a);
System.out.println("Value of b: "+b);
}
}
class Mainobj{
public static void main(String[] args) {
Constructor c = new Constructor(100,200);
c.display();
}
}
OUTPUT:
Parameterized Constructor
Value of a: 100
Value of b: 200
RESULT:
AIM:
To write a java program to get input from the user and display the details.
SOURCE CODE:
import java.util.Scanner;
class DataInput {
OUTPUT:
Thus the input from the user is obtained and the details are displayed successfully.