Java Programs Practice

Download as xlsx, pdf, or txt
Download as xlsx, pdf, or txt
You are on page 1of 7

QUESTIONS

Write a Java program to print 'Hello' on screen and your name on a separate line.
Expected Output :
Hello
Alexandra Abramov

Write a Java program to print the sum of two numbers.


Test Data:
74 + 36
Expected Output :
110

Write a Java program to divide two numbers and print them on the screen.
Test Data :
50/3
Expected Output :
16

Write a Java program to print the results of the following operations.


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

Write a Java program that takes two numbers as input and displays the product of two numbers.
Test Data:
Input first number: 25
Input second number: 5
Expected Output :
25 x 5 = 125

Write a Java program to print the sum (addition), multiply, subtract, divide and remainder of two numbers.
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
Write a Java program that takes a number as input and prints its multiplication table up to 10.
Test Data:
Input a number: 8
Expected Output :
8x1=8
8 x 2 = 16
8 x 3 = 24
...
8 x 10 = 80

Write a Java program to display the following pattern.


Sample Pattern :

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

Write a Java program to compute the specified expressions and print the output.
Test Data:
((25.5 * 3.5 - 3.5 * 3.5) / (40.5 - 4.5))
Expected Output
2.138888888888889

Write a Java program to compute a specified formula.


Specified Formula :
4.0 * (1 - (1.0/3) + (1.0/5) - (1.0/7) + (1.0/9) - (1.0/11))
Expected Output
2.9760461760461765

Write a Java program to print the area and perimeter of a circle.


Test Data:
Radius = 7.5
Expected Output
Perimeter is = 47.12388980384689
Area is = 176.71458676442586
Write a Java program that takes three numbers as input to calculate and print the average of the numbers.

Write a Java program to print the area and perimeter of a rectangle.


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) = 28.20
Write a Java program to print an American flag on the screen.
Expected Output

* * * * * * ==================================
* * * * * ==================================
* * * * * * ==================================
* * * * * ==================================
* * * * * * ==================================
* * * * * ==================================
* * * * * * ==================================
* * * * * ==================================
* * * * * * ==================================
==============================================
==============================================
==============================================
==============================================
==============================================
==============================================
Write a Java program to swap two variables.

Write a Java program to print a face.


Expected Output

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

Write a Java program to add two binary numbers.


Input Data:
Input first binary number: 10
Input second binary number: 11
Expected Output

Sum of two binary numbers: 101

Write a Java program to multiply two binary numbers.


Input Data:
Input the first binary number: 10
Input the second binary number: 11
Expected Output

Product of two binary numbers: 110

Write a Java program to convert an integer number to a binary number.


Input Data:
Input a Decimal Number : 5
Expected Output

Binary number is: 101


Write a Java program to convert a decimal number to a hexadecimal number.
Input Data:
Input a decimal number: 15
Expected Output

Hexadecimal number is : F

Write a Java program to convert a decimal number to an octal number.


Input Data:
Input a Decimal Number: 15
Expected Output

Octal number is: 17

Write a Java program to convert a binary number to a decimal number.


Input Data:
Input a binary number: 100
Expected Output

Decimal Number: 4

Write a Java program to convert a binary number to a hexadecimal number.


Input Data:
Input a Binary Number: 1101
Expected Output

HexaDecimal value: D

Write a Java program to convert a binary number to an octal number.


Input Data:
Input a Binary Number: 111
Expected Output

Octal number: 7

Write a Java program to convert a octal number to a decimal number.


Input Data:
Input any octal number: 10
Expected Output

Equivalent decimal number: 8

Write a Java program to convert a octal number to a binary number.


Input Data:
Input any octal number: 7
Expected Output

Equivalent binary number: 111


1.How to Check Given Number is Palindrome or Not
2.Find Largest Of 3 Numbers
3.Generate Fibonacci series
4.Check Given Number is Prime Or Not
5.Factorial of a Number
6.Find Sum of Elements in Array
7.How To Check The Equality Of Two Arrays
8.Find Missing Number in an Array
9.How To Find Maximum & Minimum Values in Array
10.How To Find Duplicate Elements in Array
11.Searching an Element in Array-->Linear Search
12.Searching an Element in Array | Binary Search
13.Sort Elements in Array | Bubble Sort
14.Sort Elements in Array Using Built-in Methods
15.How To Remove Junk or Special Characters in String
16.How To Count Occurrences of a Character in a String
17.How To Count Words in a String
18.How To Read Data From Text File
19.How To Write Data Into Text File
20.Swap two number using string buffer
Approach Cheat code
TC

You might also like