0% found this document useful (0 votes)
5 views

Java Programs

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Java Programs

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

class Area_Circle

{
public static void test(int r)
{
double pi = 3.14;
double res = pi * r * r;
System.out.println("Area of circle is:" + res);
}
public static void main(String[] args)
{
test(2);
}
}

—------------
class Area_Rectangle

public static void test(int a , int b)

int area = a * b;

System.out.println("Area of Rectangle:" + area);

public static void main(String[] args)

test(10,20);

—-----------------------------------

class Area_Square
{
public static void test(int side)
{
int area = side * side;
System.out.println("Area of square is:" + area);
}
public static void main(String[] args)
{
test(2);
}
}

—-----------------------------------

class Peri_Rect

public static void test(int l , int b)

int peri =2 * (l+b);

System.out.println("perimeter of rectangle is:" + peri);

public static void main(String[] args)

test(5,4);

—-------------------------------------------------------------

class Peri_Triangle
{
public static void test(int a, int b, int c)
{
int res = a + b + c;
System.out.println("Perimeter of triangle:" + res);
}
public static void main(String[] args)
{
test(1,2,3);
}
}
—-------------------------------------------------------------
class Peri_square
{
public static void test(int a)
{
int res = 4 * a;
System.out.println("Perimeter of square:" + res);
}
public static void main(String[] args)
{
test(2);
}
}
—-----------------------------------
class vol_cylinder
{
public static void test(int r,int h)
{
double pi = 3.14;
double res = pi * r * r * h;
System.out.println("Volume of a cylinder is :" + res + "cubic units");
}
public static void main(String[] args)
{
test (14,20);
}
}
—-----------------------------------
class Vol_Cube
{
public static void test(int a)
{
int res = a * a * a ;
System.out.println("volume of cube is:" + res);
}
public static void main(String[] args)
{
test (18);
}
}
—-----------------------------------
class Vol_Cuboid
{
public static void test(int l, int b, int h)
{
int res = l* b * h;
System.out.println("volume of cuboid is:" + res);
}
public static void main(String[] args)
{
test(10,20,30);
}
}
—-----------------------------------
class Area_Triangle
{
public static void test(int b, int h)
{
double res = ((b * h *100.0)/2)/100.0;
System.out.println("Area of triangle is:" + res);
}
public static void main(String[] args)
{
test(7,5);
}
}
—-----------------------------------
class LowestNum
{
public static void lowestnum(int[] a)
{
int min = a[0];
for (int i=0; i<=a.length-1; i++)
{
if (a[i]<min)
{
min = a[i];
}
}
System.out.println(min);
}
public static void main(String[] args)
{
int a1 [] = {20,60,80,10,50};
lowestnum(a1);
}
}

—-----------------------------------
class Even_odd
{
public static void test(int a)
{
if (a % 2 == 0)
{
System.out.println("The number is even");
}
else
{
System.out.println("The number is odd");
}
}
public static void main(String[] args)
{
test(2);
test(3);
}
}

—-----------------------------------

You might also like