0% found this document useful (0 votes)
2 views18 pages

Basic programs

The document contains multiple Java programs that perform various mathematical operations, such as finding the difference, product, area, and perimeter of shapes, as well as calculating averages, squares, cubes, and simple interest. Each program is structured with a main method and includes variable declarations, calculations, and output statements. The programs demonstrate basic programming concepts and arithmetic operations in Java.

Uploaded by

sulbharenge123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views18 pages

Basic programs

The document contains multiple Java programs that perform various mathematical operations, such as finding the difference, product, area, and perimeter of shapes, as well as calculating averages, squares, cubes, and simple interest. Each program is structured with a main method and includes variable declarations, calculations, and output statements. The programs demonstrate basic programming concepts and arithmetic operations in Java.

Uploaded by

sulbharenge123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

// A program to find the difference of three numbers.

import java. lang.*;


import java. util.*;
class difference
{
public static void main(String args [])
{
int a, b, c, diff;
a=20;
b=10;
c=30;
diff = a-b-c;
System.out.println (“Difference of three numbers :” + c);
}
}
// A program to find the product of three numbers.

import java. lang.*;


import java. util.*;
class product
{
public static void main(String args[])
{
int a, b, c, pro;
a=10;
b=20;
c= 30;
c=a* b* c;
System.out.println (“Product of two numbers :” + c);
}
}
// A program to find the area and perimeter of rectangle.

import java. lang.*;


import java. util.*;
class Rectangle
{
public static void main(String args[])
{
double l, b, area, perimeter;
l = 20.22;
b = 32.32;
area = l * b;
perimeter = 2 * ( l + b);
System.out.println (“Area=” + area);
System.out.println (“Perimeter=” + perimeter);
}
}
// A program to find the square of given number.

import java .lang.*;


import java .util.*;
class Square
{
public static void main(String args[])
{
int a, b;
a = 35;
b = a * a;
System.out.println (“Square=” + b);
}
}
// A program to find the Area of circle.

import java. lang.*;


import java. util.*;
class circle
{
public static void main(String args[])
{
double r, a;
r = 20.33;
a=3.14*r*r;
System.out.println (“Area=”+a);
}
}
// A program to find the Area of triangle.

import java. lang.*;


import java. util.*;
class triangle
{
public static void main(String args[])
{
double b, h, a;
b = 10.23;
h = 23.33;
a=0.5*b*h;
System.out.println(“Area=”+a);
}
}
// A program to find the Circumference of circle.

import java. lang.*;


import java. util.*;
class circle
{
public static void main(String args[])
{
double r, c;
r = 45.22;
c=2*3.14*r;
System.out.println(“Circumference=”+c);
}
}
// A program to find the Sum of squares of 2 numbers.

import java. lang.*;


import java. util.*;
class Sum
{
public static void main(String args[])
{
int m, n, s;
s=m*m + n*n;
System.out.println(“sum of squares=”+s);
}
}
// A program to find the Average of 3 numbers.

import java. lang.*;


import java. util.*;
class Average
{
public static void main(String args[])
{
double a, b, c, avg, sum;
sum = a + b + c;
avg = sum/3;
System.out.println(“Average=”+ avg);
}
}
// A program to find the cube of given numbers.

import java. lang.*;


import java. util.*;
class cube
{
public static void main(String args[])
{
int n, c;
c=n*n*n;
System.out.println(“cube=”+c);
}
}
// A program to find the Perimeter of square

import java. lang.*;


import java. util.*;
class Square
{
public static void main(String args[])
{
double s, p;
s = 66.44;
p = 4 * s;
System.out.println(“Perimeter of square=”+p);
}
}
// A program to Print series of 3 numbers.

import java. lang.*;


import java. util.*;
class Series
{
public static void main(String args[])
{
int n, a, b;
n = 20;
a=n-1;
b=n+1;
System.out.println(a+ “,”+ n + “,” +b);
}
}
// A program to Print series of 4 alternating numbers.

import java. lang.*;


import java. util.*;
class Series4
{
public static void main(String args[])
{
int n, a, b, c;
n = 12;
a = n + 2;
b = a + 2;
c = b + 2;
System.out.println(n+ “,”+ a + “,” +b + “,”+c);
}
}
// A program to convert meters into centimeter &
kilometer.

import java. lang.*;


import java. util.*;
class convert
{
public static void main(String args[])
{
double m, cm, km;
cm = m*100;
km = m/1000;
System.out.println(“Centimeter=” + cm);
System.out.println(“Kilometer=” + km);
}
}
// A program to find Simple Interest.

import java. lang.*;


import java. util.*;
class Sinterest
{
public static void main(String args[])
{
double p, r, t, si ;
p = 10.22;
r = 40.22;
t = 42.54;
si = (p * r * t)/100;
System.out.println(“Simple Interest=” + si);
}
}
// A program to find sum of square and cube of number.

import java. lang.*;


import java. util.*;
class Abc
{
public static void main(String args[])
{
int n, s, c, sum;
n = 55;
s = n * n;
c = n * n * n;
sum = s+c;
System.out.println(sum);
}
}
// A program to perform swap of two numbers with
using third variable.
import java. lang.*;
import java. util.*;
class swap
{
public static void main(String args[])
{
int a, b, c;
a = 10;
b = 20;
c = a;
a = b;
b = c;
System.out.println(a);
System.out.println(b);
}
}
// A program to perform swap of two numbers without
using third number.
import java. lang.*;
import java. util.*;
class swap
{
public static void main(String args[])
{
int a, b, c;
a = 10;
b = 20;
a = a + b;
b = a-b;
a = a-b;
System.out.println(a);
System.out.println(b);
}
}

You might also like