Access All Constants Defined in an Enum in Java

Shriansh Kumar
Updated on 19-Jun-2025 14:32:05

204 Views

After JDK version 5, Java introduced the enumeration. It is a group of constants defined using the keyword enum. The final variables in Java are somewhat similar to enumeration. In this article, we will write Java programs in which we define an enum class and try to access all the constants defined in the enum using valueOf() and values() methods. The Java Enum Class We use enum class when we need to define a fixed set of constants. For example, if we want to use the days of the week, planet names, names of all five vowels, etc. Note that all the ... Read More

Access All Data as Object Array in Java

Shriansh Kumar
Updated on 19-Jun-2025 14:23:21

212 Views

Array is a linear data structure that is used to store a group of elements with the same data type. We can create an array with primitive datatypes, and since a class is considered a user-defined datatype in Java,  it is also possible to create an array of objects. In this article, we are going to discuss object arrays. First of all, let's discuss what is an object array, in Java. What is Object array or Array of Objects An array of objects contains reference variables of objects.We follow the same syntax to create an array of primitives and an array ... Read More

Rotate the Matrix Right by K Times in Java

Shriansh Kumar
Updated on 19-Jun-2025 12:11:27

658 Views

Array is a linear data structure that is used to store a group of elements with similar data types. It stores data in a sequential manner. When we create an array of two dimensions, i.e., rows and columns, we call it a matrix. In this article, we will create a matrix of M x N and try to rotate it right by K times. Here, M and N are the size of the row and column, respectively. K is the number of times we want to rotate the matrix. Example Scenarios Let's understand what matrix rotation is with the following ... Read More

Java Program for Int to Char Conversion

Shriansh Kumar
Updated on 19-Jun-2025 12:04:26

353 Views

The given task is to write a Java program that converts an integer into a character. The int and char are primitive datatypes of Java. The int is a 32-bit signed datatype used to store whole numbers, and char holds 16-bit unsigned Unicode characters. The int and char keywords are used to declare an integer variable and a character variable, respectively. We store character variables in a single quotation (' '). Example Scenario To understand the problem statement, let's see an example scenario: Input: int num1 = 83; Output: ch = 'S' Here, num1 is the name of a ... Read More

Java Public Static Void Main String Args

Shriansh Kumar
Updated on 19-Jun-2025 11:48:14

9K+ Views

The Java program starts execution when the JVM calls the main() method. A Java application begins with this method. Without a main() method, a Java file will compile successfully because at compile time, the compiler doesn't check for a main method, but at run time JVM checks whether the main() method is available or not. Therefore, we will get an exception at run time. In this article, we will understand why we follow the convention "public static void main(String[] args)." The Syntax of a basic Java program looks like: public class class_name { // This line must be ... Read More

Java Program for Hexadecimal to Decimal Conversion

Shriansh Kumar
Updated on 19-Jun-2025 10:27:47

1K+ Views

The given task is to write a Java program to convert it into its equivalent decimal number system. The base value of hexadecimal is 16, and decimal is 10. When we convert the hexadecimal to decimal, the base value 16 will be changed to 10. The number system is of four types: Binary, Octal, Decimal, and Hexadecimal. The base value depends on the number of digits contained by the number system. For example, the binary number system contains only two digits, 0 and 1. Hence, its base is 2. Hexadecimal Number System It represents the numbers from 0 to 9 ... Read More

Calculate Difference Between Two Time Periods in Java

Shriansh Kumar
Updated on 19-Jun-2025 10:19:22

824 Views

We are given two time periods, and our task is to write a Java program to calculate the difference between them. For this problem, we can use classes and methods of java.time, java.util, and java.text packages. SimpleDateFormat class Date class LocalDate class Period class parse() method between() method As we move further in this article, we will understand the uses of these classes and methods in calculating the difference between two time periods. Some examples ... Read More

Check Number as Sum of Two Prime Numbers in Java

Shriansh Kumar
Updated on 19-Jun-2025 10:12:31

1K+ Views

The given task is to write a Java program to check if an integer can be expressed as the sum of two prime numbers. A number is said to be a prime if it has only two factors, which are 1 and itself, and cannot be divided by any other number. Some examples of prime numbers are 2, 3, 5, 7, 11, 13, and so on. 2 is the only even prime number; all other prime numbers are odd numbers. Example Scenario Let's understand the problem with an example. The possible solution is 43 = 2 + 41. Here, 2 and ... Read More

Reverse Words in a String in C++

Ravi Ranjan
Updated on 18-Jun-2025 19:19:54

6K+ Views

In this article, we have a string. Our task is to reverse the words in the given string. Here is an example of reversing the words of a string: Example The example below reverses the words of the given string: Input: "I am Viper" Output: Viper am I Here are the approaches to reverse the words of a string: Using Two Pointer Approach Using STL reverse() Function Using stringstream with Vector Using Recursive Approach ... Read More

C++ Program to Perform Finite State Automaton Based Search

Farhan Muhamed
Updated on 18-Jun-2025 19:18:27

872 Views

An automaton with a finite number of states is called a Finite Automaton. We can use a Finite State Automaton (FSA) to perform optimized pattern search operation on a string. This article will discuss how to implement a Finite State Automaton based search in C++. Problem Statement: Given two strings text[] and pattern[], we want to find all occurrences of the pattern in the text using a Finite State Automaton. // Input Strings text[] = "tutorialsPoint provides premium tutorials on various topics" pattern[] = "tutorials" // Output Pattern found at index 0 and 32 Finite State ... Read More

Advertisements