Basic Practice Programming Question in C and core Java

 1. Basic Programs

 Program to Print a String

 Program to Add two Numbers

 Program to Swap Two Numbers

 Program to Print an Integer

 Program to Add Two Binary Strings

 program to Add Two Complex numbers

 Program to Find GCD of two Numbers

 Program to Print the ASCII values

 Program to Find LCM of two Numbers

 Program to Calculate Simple Interest

 Program to Find the Area of a Circle

 Program to Find Factorial of a number

 Program to Calculate Compound Interest

 Program to Compute Quotient and Remainder

 Program to Find the Perimeter of a Rectangle

 Program to Multiply two Floating Point Numbers

 Program to Read The Number From Standard Input

 Program to Multiply Two Floating-Point Numbers

 Program to Find the Largest Among Three Numbers

 Program to Display Alphabets (A to Z) using loop

 Program to Display All Prime Numbers from 1 to N

 Program to Check Armstrong Number between Two Integers

 Program to Check whether the input number is a Neon Number

 Program to Find Even Sum of Fibonacci Series Till number N

 Program to Find all Roots of a Quadratic Equation

 Program to Calculate the Sum of Natural Numbers

 Program to Count the Number of Vowels and Consonants in a Sentence

 Program to Sort Elements in Lexicographical Order (Dictionary Order)

 Program to Calculate simple interest and compound interest

 Program to Implement multiple inheritance

 Program to Determine the name and version of the operating system

 Program to Check if two of three boolean variables are true

 Program to Iterate over enum

 Program to Check the birthday and print Happy Birthday message

 Program to Round a Number to n Decimal Places

 Program to Generate Multiplication Table

 Program to Print the Multiplication Table in Triangular Form

 Program to Display Fibonacci Series

 Program to Count Number of Digits in an Integer

 Program to Reverse a Number

 Program to Calculate the Power of a Number

 Program to Find Area of Square

 Program To Find The Area of a Trapezium

 Program to Find the Perimeter of a Circle

 Program to Find the Surface area and Volume of Cuboid

 Program To Perform nCr (r-combinations)

 Program to Find the Area of a Parallelogram



2.  Functions

 Program to Display Prime Numbers Between Two Intervals

 Program to Display Armstrong Number Between Two Intervals

 Program to Display Prime Numbers Between Intervals Using Function

 Program to Display Armstrong Numbers Between Intervals Using Function

 Program to Display Factors of a Number

 Program to Make a Simple Calculator Using switch...case

 Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers

 Program to Find the Sum of Natural Numbers using Recursion

 Program to Find Factorial of a Number Using Recursion

 Program to Find G.C.D Using Recursion

 Program to Reverse a Sentence Using Recursion

 Program to calculate the power using recursion

 Program to Call One Constructor from another

 Program to implement private constructors

 Program to pass lambda expression as a method argument

 Program to pass method call as arguments to another method

 Program to Calculate the Execution Time of Methods

 Program to Find Sum of Digits of a Number using Recursion

 Program to Find the Product of Two Numbers Using Recursion

 Program to Find Sum of N Numbers Using Recursion




3. Decision Making

 Program to Check Whether a Number is Even or Odd

 Program to Check Whether a Number is Positive or Negative

 Program to Check Whether a Character is Alphabet or Not

 Program to Check if An Array Contains a Given Value

 Program to Check Leap Year

 Program to Check Armstrong Number

 Program to Check Palindrome

 Program to Check if a String is Numeric

 Program to Check if two strings are anagram

 Program to Check Whether an Alphabet is Vowel or Consonant

 Program to Check Whether a Number is Prime or Not

 Program To Find The Perfect Number



4. Pattern Programs

 Program to Print Right Triangle Star Pattern

 Program to Print Left Triangle Star Pattern

 Program to Print Pyramid Star Pattern

 Program to Print Reverse Pyramid Star Pattern

 Program to Print Upper Star Triangle Pattern

 Program to Print Mirror Upper Star Triangle Pattern

 Program to Print Downward Triangle Star Pattern

 Program to Print Mirror Lower Star Triangle Pattern

 Program to Print Star Pascal’s Triangle

 Program to Print Diamond Star Pattern

 Program to Print Square Star Pattern

 Program to Print Pyramid Star Pattern

 Program to Print Spiral Pattern of Numbers

 Program to Create Pyramid and Pattern

 Program to Print 8 Star Pattern

 Program to Print Inverted Star Pattern

 Program to Print Hollow Right Triangle Star Pattern

 Program to Print Half Diamond Star Pattern

 Program to Print X Star Pattern



5. Conversion Programs

 Program to convert Decimal to Octal

 Program to convert Hexadecimal to Decimal

 Program to convert Decimal to Hexadecimal

 Program to convert Decimal to Binary

 Program to convert Binary to Decimal

 Program to convert Boolean to String

 Program to convert Binary to Octal

 Program to convert char type variables to int

 Program to convert int type variables to char

 Program to convert long type variables into int

 Program to convert int type variables to long

 Program to convert boolean variables into string

 Program to convert string type variables into boolean

 Program to convert string type variables into int

 Program to convert int type variables to String

 Program to convert int type variables to double

 Program to convert double type variables to int

 Program to convert string variables to double

 Program to convert double type variables to string

 Program to convert primitive types to objects

 Program to Convert a Stack Trace to a String

 Program to Convert File to byte array

 Program to Convert InputStream to String

 Program to Convert OutputStream to String

 Program to Convert Map (HashMap) to List

 Program to Convert Array to Set (HashSet)

 Program to Convert Byte Array to Hexadecimal

 Program to Convert the ArrayList to an array

 Program to Convert Character to String

 Program to Convert the InputStream into Byte Array

 Program to Convert Linked list to an Array

 Program to Convert Vector to a List

 Program to Convert String to a List of Characters

 Program to Convert Iterator to a List

 Program to Convert List to a Map

 Program to Convert List to a Stream

 Program to Convert List to Set

 Program to Convert InputStream to String

 Program to Convert Set of String to Array of String

 Program to Convert String to Object

 Program to Convert string value to byte value



6. Classes and Object Programs

 Program to Create a Class and Object

 Program to Create Abstract Class

 Program to Create Singleton Class

 Program to Create an Interface

 Program to Sow Encapsulation in Class

 Program to Show Inheritance in Class

 Program to Show Abstraction in Class

 Program to Show Data Hiding in Class

 Program to Show Polymorphism in Class

 Program to Show Overloading of Methods in Class

 Program to Show Overriding of Methods in Classes

 Program to Show Use of Super Keyword in Class

 Program to Show Use of This Keyword in Class

 Program to Show Usage of Static keyword in Class

 Program to Show Usage of Access Modifier

 Program to Add Two Complex Numbers by Passing Class to a Function

 Program to Calculate Difference Between Two Time Periods

 Program to Determine the class of an object

 Program to Create an enum class

 Program to Print object of a class

 Program to Create custom exception

 Program to Create an Immutable Class

 Program to Access private members of a class


7. Java Methods Programs

Program to Show Usage of Main() method

Program to Show Use of Static and Non-static Methods

Program to Show Usage of forEach() Method

Program to Show Usage of toString() Method

Program to Show Usage of codePointAt() Method

Program to Show Usage of compare() Method

Program to Show Usage of equals() Method

Program to Show Usage of hasNext() and next() Method

Thread Lifecycle Methods

start() Method

run() Method


8. Algorithm Programs

Program to Implement Linear Search Algorithm

Program to Implement Binary Search Algorithm

Program to Implement Bubble Sort algorithm

Program to Implement Quick Sort Algorithm

Program to Implement Merge Sort Algorithm

Program to Implement Binary Search Algorithm



9. Array Programs

Program to Print an Array

Program to Print a 2D Array

Program to Concatenate Two Arrays

Program to Search an Element in an Array

Program to Find the Largest Element in an Array

Program to Sort an Array

Program to Sort the Elements of an Array in Descending Order

Program to Sort the Elements of an Array in Ascending Order

Program to Remove Duplicate Elements From an Array

Program to Merge Two Arrays

Program to Check if Two Arrays Are Equal or Not

Program to Remove All Occurrences of an Element in an Array

Program to Find Common Array Elements

Program to Copy All the Elements of One Array to Another Array

Program For Array Rotation

Program to Add Two Matrices

Program to Sort the 2D Array Across Columns

Program to Check Whether Two Matrices Are Equal or Not

Program to Find the Transpose

Program to Find the Determinant

Program to Find the Normal and Trace

Program to Calculate Average Using Arrays

Program to Find Largest Element of an Array

Program to Calculate Standard Deviation

Program to Print Boundary Elements of a Matrix

Program to Rotate Matrix Elements

Program to Compute the Sum of Diagonals of a Matrix

Program to Interchange Elements of First and Last in a Matrix Across Rows

Program to Interchange Elements of First and Last in a Matrix Across Columns

Program to Interchange the Diagonals

Program to Add Two Matrix Using Multi-dimensional Arrays

Program to Multiply to Matrix Using Multi-dimensional Arrays

Program To Find the Trace and Normal of a given Matrix

Program to Multiply two Matrices by Passing Matrix to a Function

Program to Find Transpose of a Matrix

Program to Recursively Linearly Search an Element in an Array

Program to display upper triangular matrix

Program To Determine If a Given Matrix is a Sparse Matrix



10. String Programs

 Program to Get a Character From the Given String

 Program to Replace a Character at a Specific Index

 Program to Reverse a String

 Program to Reverse a String Using Stacks

 Program to Sort a String

 Program to Swapping Pair of Characters

 Program to Check Whether the Given String is Pangram

 Program to Print first letter of each word using regex

 Program to Determine the Unicode Code Point at a given index

 Program to Remove leading zeros

 Program to Compare two strings

 Program to Compare two strings lexicographically

 Program to Print even length words

 Program to Insert a string into another string

 Program to Splitting into a number of sub-strings

 Program to Compute all the permutations of the string

 Program to Create random strings

 Program to Clear the StringBuffer

 Program to Capitalize the first character of each word in a String

 Program to Iterate through each characters of the string.

 Program to Differentiate String == operator and equals() method

 Program to Implement switch statement on strings

 Program to Lookup enum by String value

 Program to Compare Two Strings

 Program to Convert a String into the InputStream

 Program to Check if a string contains a substring

 Program to Find the Frequency of Character in a String

 Program to Remove All Whitespaces from a String

 Program to Check if a String is Empty or Null

 Program to Check if a string is a valid shuffle of two distinct strings

 Program to Find the Duplicate Characters in a String

 Program to Replace the Spaces of a String with a Specific Character

 Program to divide a string in 'N' equal parts

 Program To Find all the Subsets of a String



11. Collection Programs

Program to Initializing a List

Program to Find a Sublist in a List

Program to Merge two lists

Program to Get Minimum and Maximum From a List

Program to Split a list into Two Halves

Program to Remove a Sublist from a List

Program to Remove Duplicates from an Array List

Program to Remove Null from a List container

Program to Sort Array list in an Ascending Order

Program to Get First and Last Elements from an Array List

Program to Convert a List of String to Comma Separated String

Program to Add Element at First and Last Position of a Linked list

Program to Find Common Elements in Two ArrayList

Program to Remove Repeated Element From An ArrayList

Program to Remove elements from the LinkedList.

Program to Add elements to a LinkedList

Program to Access elements from a LinkedList.

Program to Join Two Lists

Program to Use Different Types of a Collection

Program to Print a Collection

Program to Compare Elements in a Collection

Program to Get the Size of the Collection

Program to Compare Elements in a Collection

Program to Shuffle the Elements of a Collection

Program to Reverse a Collection

Program to Convert Collection into Array

Program to Convert Array into Collection

Program to Replace Elements in a List

Program to Rotate Elements of a List

Program to Iterate through Elements of HashMap

Program to Sort a Map By Values

Program to Sort ArrayList of Custom Objects By Property

Program to Implement LinkedList

Program to Implement stack data structure

Program to Implement the queue data structure

Program to Get the middle element of LinkedList in a single iteration

Program to Convert the LinkedList into an Array and vice versa

Program to Convert the ArrayList into a string and vice versa

Program to Iterate over an ArrayList

Program to Iterate over a HashMap

Program to Iterate over a Set

Program to Update value of HashMap using key

Program to Remove duplicate elements from ArrayList

Program to Get key from HashMap using the value

Program to Detect loop in a LinkedList

Program to Calculate union of two sets

Program to Calculate the intersection of two sets

Program to Calculate the difference between two sets

Program to Check if a set is the subset of another set

Program to Sort map by keys

Program to Pass ArrayList as the function argument

Program to Iterate over ArrayList using Lambda Expression

Program to Implement Binary Tree Data Structure

Program to Perform the preorder tree traversal

Program to Perform the postorder tree traversal

Program to Perform the inorder tree traversal

Program to Implement the graph data structure

Program to Count number of leaf nodes in a tree

Program to detect a Loop in a Linked List





12. Date and Time Programs

Program to Format time in AM-PM format

Program to Display Dates of Calendar Year in Different Format

Program to Display current Date and Time

Program to Display time in different country’s format

Program to Convert the local Time to GMT

Program to Convert String to Date

Program to Add Two Dates

Program to Convert Milliseconds to Minutes and Seconds



13. File Programs

Program to Create a new file

Program to Create a temporary file

Program to Write into a file

Program to Rename a file in java

Program to Make a File Read-Only

Program to Compare Paths of Two files

Program to Copy one file into another file

Program to Print all the Pattern that Matches Given Pattern From a File

Program to Append a String in an Existing File

Program to Read content from one file and writing it into another file

Program to Read and printing all files from a zip file

Program to Get Current Working Directory

Program to Create String from Contents of a File

Program to Append Text to an Existing File

Program to Create Directories

Program to Rename File

Program to Get all Files Present in a Directory

Program to Copy File

Program to Load File as InputStream

Program to Create File and Write to the File

Program to Read the Content of a File Line by Line

Program to Delete File in Java

Program to Delete Empty and Non-empty Directory

Program to Get the File Extension

Program to Get the name of the file from the absolute path

Program to Get the relative path from two absolute paths

Program to Count number of lines present in the file

Program to check if a file is directory or a file



14. Directory Programs

Program to Traverse in a directory

Program to Get the size of a directory

Program to Delete a directory

Program to Create directories recursively

Program to Search for a file in a directory

Program to Find the current working directory

Program to Display all the directories in a directory



15. Exceptions and Errors Programs

Program to Show Runtime exceptions

Program to Show Types of errors

Program to Handle the Exception Hierarchies

Program to Handle the Exception Methods

program to Handle the Checked exceptions

Program to Handle the Unchecked Exceptions

Program to Handle Divide By Zero and Multiple Exceptions

Program to Show Unreachable Code Error

Program to Show Thread interface and memory consistency errors



16. Multithreading Programs

Program to Check the Thread Status

Program to Suspend a Thread

Program to Join Threads

Program to Show Daemon Thread


Comments

Popular Posts