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);
}
}