Skip to content

trikmgithub/excercise-java-concepts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧩 Java Concepts Exercises

🎓 Online Training Course:
Learning Java 11 – LinkedIn Learning

🌐 Additional Resources:


📘 Exercises

  1. Sum of Two Numbers
    Write a Java program to print the sum of two numbers.
    Test Data: 74 + 36
    Expected Output: 110

  2. 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

  3. Average of Three Numbers
    Write a Java program that takes three numbers as input to calculate and print the average.

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. Reverse a String
    Write a Java program to reverse a string.
    Input Data: The quick brown fox
    Expected Output: xof nworb kciuq ehT

  10. 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
  1. 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
  1. 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

  2. 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
  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.
  1. 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

  1. Enum - Days of the Week
    Write a Java program to create an enum called DaysOfWeek representing the days of the week.

  2. 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]
  1. 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
  1. 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
  1. 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]
  1. 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
  1. Bank Account Class
    Write a Java program to create a class called BankAccount with 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 called SavingsAccount that adds an interest rate attribute and a method to apply interest.

  2. Pet Class Inheritance
    Write a Java program to create a class called Pet with attributes for name, species, and age.
    Create subclasses Dog and Bird that 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.

  3. Abstract Animal Class
    Write a Java program to create an abstract class Animal with abstract methods eat() and sleep().
    Create subclasses Lion, Tiger, and Deer that extend the Animal class and implement the methods differently based on their specific behavior.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages