0% found this document useful (0 votes)
25 views35 pages

Project Programs

The document contains Java code to solve several math problems: 1) It includes programs to find the side of a cube, potential energy, slope, velocity, and more. 2) Each program uses input from the user, performs calculations, and outputs the result. 3) The programs demonstrate how to use basic math operators, functions like pow(), and input/output in Java.

Uploaded by

mahasin
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)
25 views35 pages

Project Programs

The document contains Java code to solve several math problems: 1) It includes programs to find the side of a cube, potential energy, slope, velocity, and more. 2) Each program uses input from the user, performs calculations, and outputs the result. 3) The programs demonstrate how to use basic math operators, functions like pow(), and input/output in Java.

Uploaded by

mahasin
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/ 35

Write a program to find the side of a cube

//A program to find the side of a cube//


import java.util.*;

class Side

public static void main(String args[])

Scanner sc = new Scanner(System.in);

System.out.println("enter volume of a cube");

int v=sc.nextInt();

double a =Math.cbrt(v);

System.out.println("Volume of a cube ="+v);

System.out.println("Side of a cube ="+a);

Output:
enter volume of a cube
25

Volume of a cube =25

Side of a cube =2.924017738212866

Variable description:

Variable datatype description


v int to find volume of a
cube
a double To find side of a
cube
Write a program to calculate the potential energy

// to find potential energy

import java.util.*;

class Energy

public static void main(String args[])

Scanner sc=new Scanner(System.in);

double m,h,v;

double g=9.81;

System.out.println("Enter mass:");

m=sc.nextDouble();

System.out.println("Enter velocity:");

v=sc.nextDouble();

System.out.println("Enter height:");

h=sc.nextDouble();

double pe=m*g*h;

double ke=1.0/2.0*m*Math.pow(v,2);
double me=pe+ke;

System.out.println("Potential energy : "+pe);

System.out.println("Kinetic energy : "+ke);

System.out.println("Mechanical energy : "+me);

Output:

Enter mass:

28

Enter velocity:

Enter height:

37

Potential energy : 10163.16

Kinetic energy : 350.0

Mechanical energy : 10513.16


Variable description

Variable Data type Description


m Double To store mass
h Double To store height
v Double To store velocity
pe Double To store the values of m*h*v
ke Double To find
1.0/2.0*m*Math.pow(v,2);
me Double To add pe+ke
Write a program to calculate the square root

//To find square root

import java.util.Scanner;

class FindSquareroot

public static void main(String[] args)

int min=10,max=20;

int range = max-min+1;

int num1=(int)(range*Math.random() + min);

int num2=(int)(range*Math.random() + min);

System.out.println("First number is " + num1);

System.out.println("Second number is " + num2);

}
Output

First number is 11

Second number is 19

Variable description

Variable Data type Description


min int To generate lowest
value in the column
max int To generate highest
lowest value in the
column
range int TO subtract max and
min and add 1
Write a program to calculate slope

// to calculate the slope of a line

import java.util.*;

class slope

public static void main (String args[])

Scanner sc = new Scanner(System.in);

System.out.println("Enter x1 and y1, x2 and y2:");

int x1= sc.nextInt();

int y1= sc.nextInt();

int x2= sc.nextInt();

int y2= sc.nextInt();

double m =(y2-y1)/(x2-x1);

System.out.println("Slope=" +m);
}

Output:

Enter x1 and y1, x2 and y2:

15

11

27

28

Slope= 1.0` 1

Variable description

Variable Datatype Description


x1 int To receive x1
y1 int To receive y1
x2 int To receive x2
y2 int To receive y2
Write a program to find the velocity

//To find velocity

import java.util.*;

class Velocity

public static void main(String[] args)

Scanner in = new Scanner(System.in);

System.out.print("Enter initial velocity: ");

double u = in.nextInt();

System.out.print("Enter acceleration: ");

double a = in.nextInt();

System.out.print("Enter distance: ");

double s = in.nextInt();

double v=0;

v=Math.pow(u,2)+2*a*s;

System.out.println("Final Velocity "+Math.pow(v,2));

}
}

Output:

Enter initial velocity: 28

Enter acceleration: 14

Enter distance: 30

Final Velocity 2637376.0

Variable description

Variable Datatype Description


u double To store initial
velocity
a double To store
acceleration
s double To store distance
v double To calculate velocity
// a program to find the smallest number

import java.util.*;

class Smallest

public static void main(String args[])

Scanner sc= new Scanner (System.in);

int a,b,c,d,p;

System.out.println("Enter three numbers");

a= sc.nextInt();

b= sc.nextInt();

c= sc.nextInt();

d= Math.min(a,b);

p= Math.min(c,d);

System.out.println("Smallest number=" +p);

}
Output:

Enter three numbers

11

13

15

Smallest number=11
Variable description:

Variable Datatype Description


a int To store a number
b int To store a number
c int To store a number
d int To find the smallest
number
p int To find the smallest
number
// A program to find the diagonal of a square

import java.util.*;

class Diagonal

public static void main(String args[])

Scanner sc= new Scanner(System.in);

int a;

double d;

System.out.println("Enter side of a square");

a= sc.nextInt();

d= Math.sqrt (2)*a;

System.out.println("Side of a square=" +a);

System.out.println("Diagonal of a square=" +d);

}
Output:

Enter side of a square

11

Side of a square=11

Diagonal of a square=15.556349186104047
Variable description:

Variable datatype Description


a int to receive side of a
square
d double to receive side of a
square
// a program to find the value of an expression

import java.util.*;

class Expression

public static void main (String args[])

Scanner sc= new Scanner (System.in);

int a,b,c;

double d;

System.out.println("Enter values of a,b,c:");

a= sc.nextInt();

b= sc.nextInt();

c= sc.nextInt();

d= 1/Math.pow(a,2)+ 1/Math.pow(b,3)+
1/Math.pow(c,4);

System.out.println("The value of the given expression


is:" +d);
}

Output:

Enter values of a,b,c:

11

13

15

The value of the given expression is:0.008739382031976616

Variable description:

Variable Datatype Description


A Int To store a number
B Int To store a number
C Int To store a number
D double To store the value
of the expression
// A program to find the sum of two numbers

class Sum

public static void main(String args[])

int a,b,c =0;

a= 345; b=276;

c= a+b;

System.out.println(" The sum of two numbers =" +c);

Output:

The sum of two numbers =621


Variable description:

Variable Datatype Description


A int To store a number
B int To store a number
C int To calculate a+b

You might also like