**1.** Write a Java program to print 'Hello' on screen and then print your name on a separate line. Go to the editor

*Expected Output* :

Hello

Alexandra Abramov

**2. **Write a Java program to print the sum of two numbers. Go to the editor

Test Data:

74 + 36

*Expected Output* :

110

**3.** Write a Java program to divide two numbers and print on the screen. Go to the editor

Test Data :

50/3

*Expected Output* :

16

**4.** Write a Java program to print the result of the following operations. Go to the editor

*Test Data:*

a. -5 + 8 * 6

b. (55+9) % 9

c. 20 + -3*5 / 8

d. 5 + 15 / 3 * 2 - 8 % 3

*Expected Output* :

43

1

19

13

**5.** Write a Java program that takes two numbers as input and display the product of two numbers. Go to the editor

*Test Data:*

Input first number: 25

Input second number: 5

*Expected Output* :

25 x 5 = 125

**6.** Write a Java program to print the sum (addition), multiply, subtract, divide and remainder of two numbers. Go to the editor

*Test Data:*

Input first number: 125

Input second number: 24

*Expected Output* :

125 + 24 = 149

125 - 24 = 101

125 x 24 = 3000

125 / 24 = 5

125 mod 24 = 5

**7.** Write a Java program that takes a number as input and prints its multiplication table upto 10. Go to the editor

*Test Data:*

Input a number: 8

*Expected Output* :

8 x 1 = 8

8 x 2 = 16

8 x 3 = 24

...

8 x 10 = 80

**8.** Write a Java program to display the following pattern. Go to the editor

*Sample Pattern : *

J a v v a J a a v v a a J J aaaaa V V aaaaa JJ a a V a a

**9.** Write a Java program to compute the specified expressions and print the output. Go to the editor

*Test Data:*

((25.5 * 3.5 - 3.5 * 3.5) / (40.5 - 4.5))

*Expected Output*

2.138888888888889

**10.** Write a Java program to compute a specified formula. Go to the editor

*Specified Formula :*

4.0 * (1 - (1.0/3) + (1.0/5) - (1.0/7) + (1.0/9) - (1.0/11))

*Expected Output*

2.9760461760461765

**11.** Write a Java program to print the area and perimeter of a circle. Go to the editor

*Test Data:*

Radius = 7.5

*Expected Output*

Perimeter is = 47.12388980384689

Area is = 176.71458676442586

**12.** Write a Java program that takes three numbers as input to calculate and print the average of the numbers. Go to the editor

Click me to see the solution

**13.** Write a Java program to print the area and perimeter of a rectangle. Go to the editor

*Test Data:*

Width = 5.5
Height = 8.5

*Expected Output*

Area is 5.6 * 8.5 = 47.60

Perimeter is 2 * (5.6 + 8.5) = 47.60

**14.** Write a Java program to print an American flag on the screen. Go to the editor

*Expected Output*

* * * * * * ================================== * * * * * ================================== * * * * * * ================================== * * * * * ================================== * * * * * * ================================== * * * * * ================================== * * * * * * ================================== * * * * * ================================== * * * * * * ================================== ============================================== ============================================== ============================================== ============================================== ============================================== ==============================================

**15.** Write a Java program to swap two variables. Go to the editor

Click me to see the solution

**16.** Write a Java program to print a face. Go to the editor

*Expected Output*

+"""""+ [| o o |] | ^ | | '-' | +-----+

**17.** Write a Java program to add two binary numbers. Go to the editor

Input Data:

Input first binary number: 10

Input second binary number: 11

*Expected Output*

Sum of two binary numbers: 101

**18.** Write a Java program to multiply two binary numbers. Go to the editor

Input Data:

Input the first binary number: 10

Input the second binary number: 11

*Expected Output*

Product of two binary numbers: 110

**19.** Write a Java program to convert a decimal number to binary number. Go to the editor

Input Data:

Input a Decimal Number : 5

*Expected Output*

Binary number is: 101

**20.** Write a Java program to convert a decimal number to hexadecimal number. Go to the editor

Input Data:

Input a decimal number: 15

*Expected Output*

Hexadecimal number is : F

**21.** Write a Java program to convert a decimal number to octal number. Go to the editor

Input Data:

Input a Decimal Number: 15

*Expected Output*

Octal number is: 17

**22.** Write a Java program to convert a binary number to decimal number. Go to the editor

Input Data:

Input a binary number: 100

*Expected Output*

Decimal Number: 4

**23.** Write a Java program to convert a binary number to hexadecimal number. Go to the editor

Input Data:

Input a Binary Number: 1101

*Expected Output*

HexaDecimal value: D

**24.** Write a Java program to convert a binary number to a Octal number. Go to the editor

Input Data:

Input a Binary Number: 111

*Expected Output*

Octal number: 7

**25.** Write a Java program to convert a octal number to a decimal number. Go to the editor

Input Data:

Input any octal number: 10

*Expected Output*

Equivalent decimal number: 8

**26.** Write a Java program to convert a octal number to a binary number. Go to the editor

Input Data:

Input any octal number: 7

*Expected Output*

Equivalent binary number: 111

**27.** Write a Java program to convert a octal number to a hexadecimal number. Go to the editor

Input Data:

Input a octal number : 100

*Expected Output*

Equivalent hexadecimal number: 40

**28.** Write a Java program to convert a hexadecimal to a decimal number. Go to the editor

Input Data:

Input a hexadecimal number: 25

*Expected Output*

Equivalent decimal number is: 37

**29.** Write a Java program to convert a hexadecimal to a binary number. Go to the editor

Input Data:

Enter Hexadecimal Number : 37

*Expected Output*

Equivalent Binary Number is: 110111

**30.** Write a Java program to convert a hexadecimal to a octal number. Go to the editor

Input Data:

Input a hexadecimal number: 40

*Expected Output*

Equivalent of octal number is: 100

**31.** Write a Java program to check whether Java is installed on your computer. Go to the editor

*Expected Output*

Java Version: 1.8.0_71 Java Runtime Version: 1.8.0_71-b15 Java Home: /opt/jdk/jdk1.8.0_71/jre Java Vendor: Oracle Corporation Java Vendor URL: http://java.oracle.com/ Java Class Path: .

**32.** Write a Java program to compare two numbers. Go to the editor

Input Data:

Input first integer: 25

Input second integer: 39

*Expected Output*

25 != 39 25 < 39 25 <= 39

**33.** Write a Java program and compute the sum of the digits of an integer. Go to the editor

Input Data:

Input an integer: 25

*Expected Output*

The sum of the digits is: 7

**34.** Write a Java program to compute the area of a hexagon. Go to the editor

Area of a hexagon = (6 * s^2)/(4*tan(π/6))

where s is the length of a side

Input Data:

Input the length of a side of the hexagon: 6

*Expected Output*

The area of the hexagon is: 93.53074360871938

**35.** Write a Java program to compute the area of a polygon. Go to the editor

Area of a polygon = (n*s^2)/(4*tan(π/n))

where n is n-sided polygon and s is the length of a side

Input Data:

Input the number of sides on the polygon: 7

Input the length of one of the sides: 6

*Expected Output*

The area is: 130.82084798405722

**36.** Write a Java program to compute the distance between two points on the surface of earth. Go to the editor

Distance between the two points [ (x1,y1) & (x2,y2)]

d = radius * arccos(sin(x1) * sin(x2) + cos(x1) * cos(x2) * cos(y1 - y2))

Radius of the earth r = 6371.01 Kilometers

Input Data:

Input the latitude of coordinate 1: 25

Input the longitude of coordinate 1: 35

Input the latitude of coordinate 2: 35.5

Input the longitude of coordinate 2: 25.5

*Expected Output*

The distance between those points is: 1480.0848451069087 km

**37.** Write a Java program to reverse a string. Go to the editor

Input Data:

Input a string: The quick brown fox

*Expected Output*

Reverse string: xof nworb kciuq ehT

**38.** Write a Java program to count the letters, spaces, numbers and other characters of an input string. Go to the editor

*Expected Output*

letter: 23 space: 9 number: 10 other: 6

**39.** Write a Java program to create and display unique three-digit number using 1, 2, 3, 4. Also count how many three-digit numbers are there. Go to the editor

*Expected Output*

123 124 ... 431 432 Total number of the three-digit-number is 24

**List of Exercises with Solutions :**

- HTML CSS Exercises, Practice, Solution
- JavaScript Exercises, Practice, Solution
- jQuery Exercises, Practice, Solution
- jQuery-UI Exercises, Practice, Solution
- CoffeeScript Exercises, Practice, Solution
- Twitter Bootstrap Exercises, Practice, Solution
- C Programming Exercises, Practice, Solution
- C# Sharp Programming Exercises, Practice, Solution
- PHP Exercises, Practice, Solution
- Python Exercises, Practice, Solution
- Java Exercises, Practice, Solution
- SQL Exercises, Practice, Solution
- MySQL Exercises, Practice, Solution
- PostgreSQL Exercises, Practice, Solution
- SQLite Exercises, Practice, Solution
- MongoDB Exercises, Practice, Solution
- Euler Project

**Join our Question Answer community to learn and share your programming knowledge.**

**Help the community:**

**C++:** Decimal to binary conversion

**JavaScript:** Need Help in JavaScript

**Python: **Help me with this program