Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

1.

Write a Java program that produces the following output:


I am
a
Beginner to Java
World
2. Write a Java program that store two integer variables in the memory. Calculate and display all
arithmetic operation results (addition +, subtraction -, multiplication *, division / & modulus %).
3. Write a Java program that prompt the user to input the length and width of a rectangle. Calculate
and display the Perimeter and Area of the rectangle.
𝑃𝑒𝑟𝑖𝑚𝑒𝑡𝑒𝑟 = 2 × (𝑙𝑒𝑛𝑔𝑡ℎ + 𝑤𝑖𝑑𝑡ℎ)
𝐴𝑟𝑒𝑎 = 𝑙𝑒𝑛𝑔𝑡ℎ × 𝑤𝑖𝑑𝑡ℎ
4. Write a program that prompts the user to input a number. The program should then output the
number and a message saying whether the number is positive, negative, or zero.
5. Write a program that mimics a calculator. The program should take as input two integers and the
operation to be performed. It should then output the numbers, the operator, and the result. (For
division, if the denominator is zero, output an appropriate message.) Some sample inputs and
outputs follow:
Input: Number1: 3 Number2: 4 Operator: +
Output: 3+4=7
Input: Number1: 13 Number2: 5 Operator: *
Output: 13 * 5 = 65
6. Write a program that prompts the user to enter 10 positive integers and print the maximum value
among it.
7. Write a program that prompts the base and exponent from the user and display the power of the
number.
𝑝𝑜𝑤𝑒𝑟 = 𝑏𝑎𝑠𝑒 𝑒𝑥𝑝𝑜𝑛𝑒𝑛𝑡
8. Write a program that prompts the user to enter a positive integer and find its factorial.
9. Write a program that prompts the user to input an integer and then outputs both the individual
digits of the number and the sum of the digits.
For example, it should output the individual digits of 3456 as 3 4 5 6,
output the individual digits of 8030 as 8 0 3 0,
output the individual digits of 2345526 as 2 3 4 5 5 2 6,
output the individual digits of 4000 as 4 0 0 0, and
output the individual digits of -2345 as 2 3 4 5.
10. Write a program that prompts the user to input an integer and then outputs the number with the
digits reversed.
For example, if the input is 12345, the output should be 54321.
Your program must also output 5000 as 0005 and 980 as 089.

You might also like