Mathematical Programming Test

Here are some most common formulae based mathematical programs. These programming test is basically for checking the mathematical knowledge and Java operator precedence to implement these formulae.

  1. Program to calculate the area of rectangle
    Input: Width = 10; Height = 5
    Output:
    Area of Rectangle = Width * Height
    = 10 * 5
    = 50
  2. Program to calculate the volume of sphere
    Input:Radius = 48; Pie = 3.14
    Output:
    Volume = (4.0/3.0) * pie * (radius * radius * radius);
    = (4.0/3.0) * 3.14 * 48 * 48 * 48
    = 463433.132812
  3. Program find the area of the pentagon
    Input:s = 13; a = 5;
    Output:
    Area of Pentagon = (5.0/2.0) * s * a
    = (5.0/2.0) * 13 * 5
    = 162.5
  4. Program to find the area of parallelogram
    Input:base = 4; height = 18;
    Output:
    Area of Parallelogram = base * height;
    = 4 * 18
    = 72
  5. Program to find the area of square
    Input:a = 13
    Output:
    Area of Square = a2
    = 132
    = 169
  6. Program to find the surface area of sphere
    Input:Radius = 37, Pie = 3.14
    Output:
    Volume = 4 * pie * (radius * radius);
    = 4 * 3.14 * 37 * 37
    = 17210.285714
  7. Program to find the volume of cone
    Input:Radius = 38, Height = 35, Pie = 3.14
    Output:
    Volume = pie * radius * radius * height/3;
    = 3.14 * 38 * 38 * 35/3
    = 48766.666667
  8. Program to find the volume of the cube
    Input:side = 4
    Output:
    Volume of cube = side3
    = 43
    = 64
  9. Program to find the volume of cylinder
    Input:radius (r) = 38 , height (h) = 35
    Output:
    Volume of the cylinder = pie * radius2 * height
    = 3.14 * 38* 38 * 35
    = 146300.000000
  10. Program to calculate the CGPA percentage
    CGPA percentage is = (float)(9.5 * (CGPA));
    Input:
    CGPA = (Grades in all Subjects) / (Total Number of Subjects).
    English = 9.1;
    Hindi = 8.5;
    Maths = 9.5;
    Science =9.6;
    SocialStudy = 8.6;
    CGPA = (9.1+8.5+9.5+9.6+8.6)/(5.0);
    Output:CGPA percentage is = 86.070000
  11. Program to convert Celsius into Fahrenheit
    Temperature in Fahrenheit = ((celsius * 9) / 5) + 32
    Input:celsius= 12
    Output:Temperature in Fahrenheit = 53.6
  12. Program to convert days into years
    Input:days= 799;
    Output:
    Number of years = days / 365;
    = 799 / 365
    = 2
  13. Program to convert Fahrenheit into Celsius
    Temperature in Celsius = ((Fahrenheit-32)*5)/9
    Input:Fahrenheit = 54
    Output:Temperature in Celsius= ((54-32)*5)/9 = 12.22222
  14. Program to find the area of an equilateral triangle
    Input:side (a) = 5
    Output:
    Area of Equilateral Triangle = ( 1.73 * a * a) / 4
    = ( 1.73 * 5 * 5) / 4
    = 10.81250
  15. Program to find the area of a triangle
    Input:b = 5; h = 12
    Output:Area of Triangle = (b * h) / 2
    = (5 * 12) / 2
    = 30.0
  16. Program to find the area of the right angle triangle
    Input:b = 5; h = 8
    Output:Area of Triangle = (b * h) / 2
    = (5 * 8) / 2
    = 20.0
  17. Program to find the perimeter of the rectangle
    Input:a = c = 5
    b = d = 4
    Output:Perimeter of Rectangle = 2 * ( a + b);
    = 2 * (5 + 4)
    = 18.00000
  18. Program to find the simple interest
    Simple Interest = (P × R × T) / 100
    Input:P = 34000, R = 30,T = 5
    where P = Principal Amount, R = Rate per Annum, T = Time (years)
    Output: Simple Interest = 51000.000
  19. Program to find the surface area of a cube
    Surface Area Of Cube = 6 ( a * a )
    Input:b = 5, h = 5
    a (side) = length = breadth = height
    Output:Surface Area Of Cube = 6 * 5 * 5=150.00000
  20. Program to find the surface area of sphere
    Input:l= 2, w = 3, h = 5;
    where l = length, w = width and h = height.
    Output:
    Surface Area OfCuboid = 2 * (l * w+ w * h + h * l)
    = 2 * (2 * 3 + 3 * 5 + 5 * 2)
    = 62.00000
  21. Program to find the surface area of the cylinder
    Surface Area of Cylinder = 2 Π (r + h)
    Input:r = 2.0, h = 5.0
    Output:
    Surface Area of Cylinder = 2 Π (r + h)
    Here, r = radius, h = height, and Π ( pie ) = 3.14
    = 2 * 3.14 * ( 2.0 + 5.0)
    = 44.00000
  22. Write a Java program to compute the area of a hexagon.
    Area of a hexagon = (6 * s^2)/(4*tan(π/6))
    where s is the length of a side
    Input: Input the length of a side of the hexagon: 6
    Output: The area of the hexagon is: 93.53074360871938
  23. Write a Java program to compute the area of a polygon.
    Area of a polygon = (n*s^2)/(4*tan(π/n))
    where n is n-sided polygon and s is the length of a side
    Input:
    Input the number of sides on the polygon: 7
    Input the length of one of the sides: 6
    Output: The area is: 130.82084798405722
  24. Write a Java program to compute the distance between two points on the surface of earth.
    Distance between the two points [ (x1,y1) & (x2,y2)]
    d = radius * arccos(sin(x1) * sin(x2) + cos(x1) * cos(x2) * cos(y1 – y2))
    Radius of the earth r = 6371.01 Kilometers
    Input:
    Input the latitude of coordinate 1: 25
    Input the longitude of coordinate 1: 35
    Input the latitude of coordinate 2: 35.5
    Input the longitude of coordinate 2: 25.5
    Output: The distance between those points is: 1480.0848451069087 km