🎓 Online Training Course:
Learning Java 11 – LinkedIn Learning
🌐 Additional Resources:
-
Sum of Two Numbers
Write a Java program to print the sum of two numbers.
Test Data: 74 + 36
Expected Output: 110 -
Arithmetic Operations
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 -
Average of Three Numbers
Write a Java program that takes three numbers as input to calculate and print the average. -
Binary Multiplication
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 -
Decimal to Hexadecimal Converter
Write a Java program to convert a decimal number to a hexadecimal number.
Input Data: 15
Expected Output:Hexadecimal number is : F -
Binary to Hexadecimal Converter
Write a Java program to convert a binary number to a hexadecimal number.
Input Data: 1101
Expected Output:HexaDecimal value: D -
Octal to Binary Converter
Write a Java program to convert an octal number to a binary number.
Input Data: 7
Expected Output:Equivalent binary number: 111 -
Sum of Digits
Write a Java program and compute the sum of an integer's digits.
Input Data: 25
Expected Output:The sum of the digits is: 7 -
Reverse a String
Write a Java program to reverse a string.
Input Data: The quick brown fox
Expected Output:xof nworb kciuq ehT -
Count Characters in String
Write a Java program to count letters, spaces, numbers and other characters in an input string.
Expected Output:
The string is : Aa kiu, I swd skieo 236587. GH kiu: sieo?? 25.33
letter: 23
space: 9
number: 10
other: 6
- File Size Finder
Write a Java program to find the size of a specified file.
Sample Output:
/home/students/abc.txt : 0 bytes
/home/students/test.txt : 0 bytes
-
Formatted Date and Time
Write a Java program to display the current date and time in a specific format.
Sample Output:
Now: 2017/06/16 08:52:03.066 -
Check Even or Odd
Write a Java program to accept a number and check whether the number is even or not. Prints 1 if even or 0 if odd.
Sample Output:
Input a number: 20
1
- Capitalize Each Word
Write a Java program to capitalize the first letter of each word in a sentence.
Sample Output:
Input a Sentence: the quick brown fox jumps over the lazy dog.
The Quick Brown Fox Jumps Over The Lazy Dog.
- First and Last of Two Arrays
Write a Java program to test if the first and last element of two integer arrays are the same.
Test Data:
array1 = 50, -20, 0, 30, 40, 60, 12
array2 = 45, 20, 10, 20, 30, 50, 11
Sample Output: false
-
Enum - Days of the Week
Write a Java program to create an enum calledDaysOfWeekrepresenting the days of the week. -
Rotate Array Left
Write a Java program to rotate an array (length 3) of integers in the left direction.
Sample Output:
Original Array: [20, 30, 40]
Rotated Array: [30, 40, 20]
- Largest of First or Last Element
Write a Java program to get the largest value between the first and last elements of an array (length 3).
Sample Output:
Original Array: [20, 30, 40]
Larger value between first and last element: 40
- Remove Duplicates (At Most Twice)
Write a Java program to find the updated length of a given sorted array where duplicate elements appear at most twice.
Original array: [1, 1, 2, 3, 3, 3, 4, 5, 6, 7, 7, 7, 7]
The length of the original array is: 13
After removing duplicates, the new length of the array is: 10
- Move Zeros to Right
Write a Java program to move every zero to the right side of a given array of integers.
Original array: [0, 3, 4, 0, 1, 2, 5, 0]
Result: [3, 4, 1, 2, 5, 0, 0, 0]
- Test Substring in String
Write a Java program to accept two strings and test if the second string contains the first one.
Input first string: Once in a blue moon
Input second string: See eye to eye
If the second string contains the first one? False
-
Bank Account Class
Write a Java program to create a class calledBankAccountwith attributes for account number, account holder's name, and balance.
Include methods for depositing and withdrawing money, as well as checking the balance.
Create a subclass calledSavingsAccountthat adds an interest rate attribute and a method to apply interest. -
Pet Class Inheritance
Write a Java program to create a class calledPetwith attributes for name, species, and age.
Create subclassesDogandBirdthat add specific attributes like favorite toy for dogs and wing span for birds.
Implement methods to display pet details and calculate the pet's age in human years. -
Abstract Animal Class
Write a Java program to create an abstract classAnimalwith abstract methodseat()andsleep().
Create subclassesLion,Tiger, andDeerthat extend theAnimalclass and implement the methods differently based on their specific behavior.