1. Add Two Integers Easy
Problem
Write a program to add two integers.
Input Format
- The first line contains a single integer
m
. - The second line contains a single integer
n
.
Output Format
Print the sum of the integers m
and n
.
Sample Input 1
5
10
Sample Output 1
15
Code
import java.util.Scanner;
class AddTwoIntegers {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int sum = m + n;
System.out.println(sum);
}
}
2. Add Three Integer Numbers Easy
Problem
Write a program to add three integers.
Input Format
- The first line contains a single integer
m
. - The second line contains a single integer
n
. - The third line contains a single integer
p
.
Output Format
Print the sum of the integers m
, n
, and p
.
Sample Input 1
10
15
5
Sample Output 1
30
Code
import java.util.Scanner;
class AddThreeIntegers {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int p = sc.nextInt();
int sum = m + n + p;
System.out.println(sum);
}
}
3. Product of Three Integer Numbers Medium
Problem
Write a program to calculate the product of three integers.
Input Format
- The first line contains a single integer
a
. - The second line contains a single integer
b
. - The third line contains a single integer
c
.
Output Format
Print the product of the integers a
, b
, and c
.
Constraints
−1000≤a,b,c≤1000
Sample Input 1
2
3
4
Sample Output 1
24
Code
import java.util.Scanner;
class ProductThreeIntegers {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int product = a * b * c;
System.out.println(product);
}
}
4. Write a Program for Sum Combinations Easy
Problem
Write a program to calculate the sum combinations of three integers.
Input Format
- The first line contains a single integer
a
. - The second line contains a single integer
b
. - The third line contains a single integer
c
.
Output Format
Print the sums of the combinations a + b
, a + c
, and b + c
.
Constraints
0≤a,b,c≤1000
Sample Input 1
2
3
4
Sample Output 1
5
6
7
Code
import java.util.Scanner;
class SumCombination {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
System.out.println(a + b);
System.out.println(a + c);
System.out.println(b + c);
}
}
5. Calculate Circle’s Circumference Medium
Problem
Write a program to calculate the circumference of a circle using the formula C = 2Ï€r
, where π ≈ 3.14159
.
Input Format
- The first line contains a single
r
(the radius of the circle).
Output Format
Print the circumference of the circle, formatted to four decimal places.
Constraints
1≤radius≤10000
Sample Input 1
5
Sample Output 1
31.4159
Code
import java.util.Scanner;
class CircleCircumference {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double radius = sc.nextDouble();
double pi = 3.14159;
double circumference = 2 * pi * radius;
System.out.printf("%.4f%n", circumference);
}
}
6. Convert Dollar to Rupees Easy
Problem
Write a program to convert US dollars to Indian rupees. The conversion rate is 1 USD = 82.73 INR.
Formula
INR = USD * 82.73
Input Format
- The first line contains a single floating-point number
USD
.
Output Format
Print the equivalent amount in Indian rupees (INR).
Constraints
0.01 ≤ USD ≤ 10000
Sample Input 1
100
Sample Output 1
8273.00
Code
import java.util.Scanner;
class DollarToRupees {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double usd = sc.nextDouble();
double inr = usd * 82.73;
System.out.println(inr);
}
}
7. Find the Perimeter of a Rectangle Easy
Problem
Write a program to calculate the perimeter of a rectangle using the formula.
Formula
Perimeter = 2 * (length + width)
Input Format
- The first line contains a single integer
length
. - The second line contains a single integer
width
.
Output Format
Print the perimeter of the rectangle.
Constraints
1 ≤ length, width ≤ 1000
Sample Input 1
5
3
Sample Output 1
16
Code
import java.util.Scanner;
class RectanglePerimeter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int length = sc.nextInt();
int width = sc.nextInt();
int perimeter = 2 * (length + width);
System.out.println(perimeter);
}
}
8. Find the Area of a Circle Easy
Problem
Write a program to calculate the area of a circle using the formula.
Formula
Area = π * radius^2
, where π ≈ 3.14159
Input Format
- The first line contains a single integer
radius
.
Output Format
Print the area of the circle.
Constraints
1 ≤ radius ≤ 10000
Sample Input 1
5
Sample Output 1
78.53975
Code
import java.util.Scanner;
class CircleArea {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double radius = sc.nextDouble();
double area = 3.14159 * radius * radius;
System.out.println(area);
}
}
9. Find the Total Surface Area of a Cylinder Medium
Problem
Write a program to calculate the total surface area of a cylinder.
Formula
Total Surface Area = 2Ï€r(h + r)
, where π ≈ 3.14159
Input Format
- The first line contains a single integer
radius
. - The second line contains a single integer
height
.
Output Format
Print the total surface area of the cylinder.
Constraints
1 ≤ radius, height ≤ 1000
Sample Input 1
5
10
Sample Output 1
471.2385
Code
import java.util.Scanner;
class CylinderSurfaceArea {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double radius = sc.nextDouble();
double height = sc.nextDouble();
double surfaceArea = 2 * 3.14159 * radius * (height + radius);
System.out.println(surfaceArea);
}
}
10. Find the Perimeter of a Square Easy
Problem
Write a program to calculate the perimeter of a square using the formula.
Formula
Perimeter = 4 * side
Input Format
- The first line contains a single integer
side
.
Output Format
Print the perimeter of the square.
Constraints
1 ≤ side ≤ 1000
Sample Input 1
4
Sample Output 1
16
Code
import java.util.Scanner;
class SquarePerimeter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int side = sc.nextInt();
int perimeter = 4 * side;
System.out.println(perimeter);
}
}
11. Convert Fahrenheit to Celsius Easy
Problem
Write a program to convert a temperature from Fahrenheit to Celsius.
Formula
Celsius = (Fahrenheit - 32) * 5/9
Input Format
- The first line contains a single floating-point number
Fahrenheit
.
Output Format
Print the equivalent temperature in Celsius.
Constraints
-1000 ≤ Fahrenheit ≤ 1000
Sample Input 1
98.6
Sample Output 1
37.0
Code
import java.util.Scanner;
class FahrenheitToCelsius {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double fahrenheit = sc.nextDouble();
double celsius = (fahrenheit - 32) * 5 / 9;
System.out.println(celsius);
}
}
12. Calculate Simple Interest Medium
Problem
Write a program to calculate simple interest using the formula.
Formula
SI = (P * R * T) / 100
, where:
P
is the principal amountR
is the rate of interestT
is the time in years
Input Format
- The first line contains a single integer
P
. - The second line contains a single floating-point number
R
. - The third line contains a single integer
T
.
Output Format
Print the simple interest.
Constraints
1 ≤ P, T ≤ 10000
0.01 ≤ R ≤ 20.00
Sample Input 1
1000
5.5
2
Sample Output 1
110.0
Code
import java.util.Scanner;
class SimpleInterest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int P = sc.nextInt();
double R = sc.nextDouble();
int T = sc.nextInt();
double SI = (P * R * T) / 100;
System.out.println(SI);
}
}