JAVA PROGRAMS
MADE BY- AARYA
INTRODUCTION TO JAVA
Java is an object oriented programming language
developed in January 1996 by a team of Sun
Microsystems, headed by James Gosling. Later on,
in 2010, it was acquired by Oracle.
INTRODUCTION TO BLUEJ AND ITS
FEATURES
Bluej is an IDE(Integrated Development Environment) for beginners to
write, edit and execute the Java programs. It allows students to write
programs using an interactive visual environment, which gives them a
good understanding of the programming concept.
Bluej includes:
AN EDITOR, which you use to write your programs.
A DEBUGGER, to help you find your mistakes.
A VIEWER, to see the parts of your program.
An easy way to run Java programs.
An easy way to view documentation.
PROGRAMS
1. Write a program to print your name and class.
//To print name and class
class name
{
public static void main()
{
System.out.println("My name is Aarya");
System.out.println("I study in VIII-B");
}
}
OUTPUT
2. Write a program to assign 10 and 5 in two different variables.
Print the sum, difference, product, quotient and remainder.
//To do mathematical operations
class maths
{
public static void main()
{
int a=10, b=5;
int z=a+b;
int y=a-b;
int x=a*b;
int w=a/b;
int v=a%b;
System.out.println("Sum is "+z);
System.out.println("Difference is "+y);
System.out.println("Product is " +x);
System.out.println("Quotient is "+w);
System.out.println("Remainder is "+v);
}}
OUTPUT
3. Write a program to input a number and find the square root
and cube root of the number.
// TO PRINT THE SQUARE ROOT AND CUBE ROOT OF A NUMBER
class root
{
public static void main(int a) a
{
double x=Math.sqrt(a); 64
double y=Math.cbrt(a);
System.out.println("THE SQUARE ROOT IS " +x);
System.out.println("THE CUBE ROOT IS "+y);
}
}
OUTPUT
4. Write a program to input the side of a square and find the
area and perimeter of the square.
// TO PRINT THE AREA AND PERIMETER OF A SQUARE
class square
{ s
public static void main(int s) 12
{
double x=Math.pow(s,2);
double y=4*s;
System.out.println("THE AREA OF THE SQUARE IS " +x);
System.out.println("THE PERIMETER OF THE SQUARE IS " +y);
}
}
OUTPUT
5. Write a program to input the length and breadth of a
rectangle and find the area and perimeter of the rectangle.
// TO PRINT THE AREA AND PERIMETER OF A RECTANGLE
class rectangle
{
public static void main(int l,int b)
{ l,b
int x=l*b; 24,12
int y=2*(l+b);
System.out.println("THE AREA OF THE RECTANGLE IS " +x);
System.out.println("THE PERIMETER OF THE RECTANGLE IS " +y);
}
}
OUTPUT
6. Write a program to input a number and find the square and
cube of the number.
//TO PRINT THE SQUARE AND CUBE OF A NUMBER
class sqandcb n
{ 12
public static void main(int n)
double square=Math.pow(n,2);
double cube=Math.pow(n,3);
System.out.println("THE SQUARE IS " +square);
System.out.println("THE CUBE IS " +cube);
}}
OUTPUT
7. Write a program to input two numbers and find the biggest and the
smallest number.
//To print the smallest and biggest number
class smallbig
{ a,b
public static void main(int a, int b) 348,457
{
double x=Math.min(a,b);
double y=Math.max(a,b);
System.out.println("Smallest number is "+x);
System.out.println("Biggest number is "+y);
OUTPUT
8. Write a program to input the cost of one shirt and find the cost
of five shirts.
//To print the cost of 5 shirts
class shirt cost
{ 798.76
public static void main(double cost)
double a=5*cost;
System.out.println("The cost of 5 shirts is "+a);
OUTPUT
9. Write a program to input three numbers and find their sum
and average.
//TO PRINT THE SUM AND AVERAGE OF THREE NUMBERS
class sumage
public static void main(int a, int b, int c) a,b,c
{ 25,32,48
int sum=a+b+c;
double average=(a+b+c)/3;
System.out.println("The sum is "+sum);
System.out.println("The average is "+average);
OUTPUT
10. Write a program to input appropriate values and find
√a + 𝒄𝒃 + |a|.
//TO PRINT THE OUTPUT OF A MATHEMATICAL EXPRESSION
class expression
public static void main(int a, int b, int c)
{ a,b,c
double result=Math.sqrt(a)+Math.pow(c,b)+Math.abs(a); 25,3,5
System.out.println("The output is "+result);
OUTPUT
11. Write a program to input three sides of a triangle and find its
area.
//To print the area of a triangle
a,b,c
class triangle
{ 12,14,17
public static void main(int a, int b, int c)
{
double s=(a+b+c)/2;
double x=Math.sqrt(s*(s-a)*(s-b)*(s-c));
System.out.println("The area of the triangle is "+x);
}
}
OUTPUT
12. Write a program to input the principal, rate and time and
print the simple interest.
// TO PRINT THE SIMPLE INTEREST
p,r,t
class interest
12670.0, 3.5, 2
{
public static void main(double p, double r, int t)
double y=(p*r*t)/100;
System.out.println("The simple interest is "+y);
OUTPUT
13. Write a program to print your name four times in the same line.
//To print your name four times in the same line
class name
public static void main()
System.out.print("AARYA "+"AARYA "+"AARYA "+"AARYA");
OUTPUT
14. Write a program to input two angles of a triangle and find the
third angle.
//To print the third angle of a triangle
class angle
public static void main(int A, int B) A, B
{ 35, 45
int C=180-(A+B);
System.out.println("The third angle of the triangle is "+C);
OUTPUT
15. Write a program to input the radius of a circle and find its area
and circumference.
//To print the area and circumference of a circle
class circle
public static void main(int r) r
{ 12
double area=(22/7)*Math.pow(r,2);
double circum=2*(22/7)*r;
System.out.println("The circumference of the circle is "+circum);
System.out.println("The area of the circle is "+area);
OUTPUT
16. Write a program to input three numbers and find their absolute
values.
//To find the absolute values of three numbers
class values
public static void main(int a, double b, int c) a,b,c
{ -12,46.9,
-23
int y=Math.abs(a);
double z=Math.abs(b);
int v=Math.abs(c);
System.out.println("The absolute value of a is "+y);
System.out.println("The absolute value of b is "+z);
System.out.println("The absolute value of c is "+v);
OUTPUT
17. Write a program to input the side of a cube and find its volume
and surface area.
//To print the volume and surface area of a cube
class cube
public static void main(int s)
{ s
double x=Math.pow(s,3); 20
double y=6*Math.pow(s,2);
System.out.println("The volume of the cube is "+x);
System.out.println("The surface area of the cube is "+y);
OUTPUT
18. Write a program to input the length, breadth and height of a
cuboid and find its volume and surface area.
//To print the volume and surface area of a cuboid
class cuboid
public static void main(int l, int b, int h)
{ l,b,h
double x=l*b*h; 6,4,3
double y=2*((l*b)+(b*h)+(h*l));
System.out.println("The volume of the cuboid is "+x);
System.out.println("The surface area of the cuboid is "+y);
}}
OUTPUT
19. Write a program to evaluate the result of |-16| + |-45.67| - 8.
//To evaluate the result
class maths
public static void main()
int a=-16;
double b=-45.67;
int c=8;
double f=Math.abs(a)+Math.abs(b)-c;
System.out.println("The result is "+f);
OUTPUT
20. Write a program to input appropriate values and find
𝟑 𝒃
√𝒂 + + 𝒄 2.
𝒄
//To evaluate the result
class maths_
public static void main(int a, int b, int c) a,b,c
{ 125,4,2
double f=Math.cbrt(a)+(b/c)+Math.pow(c,2);
System.out.println("The result is "+f);
OUTPUT