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

Java Programs

The document contains Java programs for various mathematical calculations, including the sum of two numbers, area and perimeter of a rectangle, area and circumference of a circle, temperature conversion from Celsius to Fahrenheit, diagonal of a rectangle, sum and average of three numbers, simple interest calculation, and converting seconds into hours, minutes, and seconds. Each program prompts the user for input and outputs the calculated result. Additionally, there is a program to calculate specific values based on user-defined variables.

Uploaded by

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

Java Programs

The document contains Java programs for various mathematical calculations, including the sum of two numbers, area and perimeter of a rectangle, area and circumference of a circle, temperature conversion from Celsius to Fahrenheit, diagonal of a rectangle, sum and average of three numbers, simple interest calculation, and converting seconds into hours, minutes, and seconds. Each program prompts the user for input and outputs the calculated result. Additionally, there is a program to calculate specific values based on user-defined variables.

Uploaded by

swapnaneelbose10
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Sum of Two Numbers


Solution:

import [Link].*;
class Sum
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
double a, b, sum;
[Link]("Enter first number: ");
a = [Link]();
[Link]("Enter second number: ");
b = [Link]();
sum = a + b;
[Link]("Sum = " + sum);
}
}
2. Area and Perimeter of a Rectangle

Solution:
import [Link].*;
class Rectangle
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
double length, breadth, area, perimeter;
[Link]("Enter length: ");
length = [Link]();
[Link]("Enter breadth: ");
breadth = [Link]();
area = length * breadth;
perimeter = 2 * (length + breadth);
[Link]("Area = " + area);
[Link]("Perimeter = " + perimeter);
}
}
3. Area and Circumference of a Circle
Solution:

import [Link].*;
class Circle
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
double radius, area, circumference;
[Link]("Enter radius: ");
radius = [Link]();
area = 3.14 * radius * radius;
circumference = 2 * 3.14 * radius;
[Link]("Area = " + area);
[Link]("Circumference = " + circumference);
}
}
4. Celsius to Fahrenheit
Solution:

import [Link].*;
class Temperature
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
double c, f;
[Link]("Enter temperature in Celsius: ");
c = [Link]();
f = (9 * c / 5) + 32;
[Link]("Temperature in Fahrenheit = " + f);
}
}
5. Diagonal of a Rectangle
Solution:

import [Link].*;
class Diagonal
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
double length, breadth, diagonal;
[Link]("Enter length: ");
length = [Link]();
[Link]("Enter breadth: ");
breadth = [Link]();
diagonal = [Link](length * length + breadth * breadth);
[Link]("Diagonal = " + diagonal);
}
}
6. Sum and Average of Three Numbers

Solution:

import [Link].*;
class Average
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
double a, b, c, sum, average;
[Link]("Enter first number: ");
a = [Link]();
[Link]("Enter second number: ");
b = [Link]();
[Link]("Enter third number: ");
c = [Link]();
sum = a + b + c;
average = sum / 3;
[Link]("Sum = " + sum);
[Link]("Average = " + average);
}
}
7. Simple Interest
Solution:

import [Link].*;
class SimpleInterest
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
double p, r, t, si;
[Link]("Enter Principal: ");
p = [Link]();
[Link]("Enter Rate: ");
r = [Link]();
[Link]("Enter Time: ");
t = [Link]();
si = (p * r * t) / 100;
[Link]("Simple Interest = " + si);
}
}
8. Calculate x and y

Solution:
import [Link].*;
class Calculate
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int a, b, x, y;
[Link]("Enter value of a: ");
a = [Link]();
[Link]("Enter value of b: ");
b = [Link]();
x = a * a + b * b * b;
y = b * b * b - a * a;
[Link]("x = " + x);
[Link]("y = " + y);
}
}
9. Convert Seconds into Hours, Minutes and Seconds

Solution:
import [Link].*;
class Time
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
int seconds, hours, minutes, sec;
[Link]("Enter seconds: ");
seconds = [Link]();
hours = seconds / 3600;
minutes = (seconds % 3600) / 60;
sec = seconds % 60;
[Link]("Hours = " + hours);
[Link]("Minutes = " + minutes);
[Link]("Seconds = " + sec);
}
}
10. Volume of a Cylinder

Solution:
import [Link].*;
class Cylinder
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]);
double radius, height, volume;
[Link]("Enter radius: ");
radius = [Link]();
[Link]("Enter height: ");
height = [Link]();
volume = 3.14 * radius * radius * height;
[Link]("Volume = " + volume);
}
}

You might also like