Found 9178 Articles for Object Oriented Programming

Java ArrayList to print all possible words from phone digits

Neetika Khandelwal
Updated on 24-Oct-2024 19:27:59

378 Views

In this article, we will learn to generate all possible words from a string of phone digits using Java. Each digit on a mobile keypad corresponds to a set of letters, and our task is to find every possible combination of letters that can be formed by pressing those digits. For instance, if the input is "23, " the output would include combinations like "ad, " "ae, " "af, " and so on. We will implement a recursive approach to achieve this, allowing us to systematically generate and print all possible words corresponding to the given digits. Problem Statement Write ... Read More

Generate a String Consisting of Characters ‘a’ and ‘b’ that Satisfy the given Conditions

Neetika Khandelwal
Updated on 22-Aug-2023 17:43:57

456 Views

The task is to generate a string that consists of characters ‘a’ and ‘b’ which satisfies the condition mentioned below: str must have a length of A+B. The character 'a' must appear A times and the character 'b' must appear B times within the string. The sub−strings "aaa" and "bbb" should not appear in str. After generating the string, it should be printed. One possible solution is to first generate a string with all 'a's and 'b's, with 'a' occurring A times and 'b' occurring B times. Then, we can shuffle the string randomly until we find a ... Read More

Java program for longest subsequence of a number having same left and right rotation

Shubham Vora
Updated on 23-Jan-2025 23:07:33

196 Views

In this tutorial, we will learn how to find the maximum length of the subsequence having the same left and right rotations in Java. We find the maximum length of such subsequence. Finding the longest subsequence with identical or alternating digits We will solve the problem based on a particular observation. The strings can only have the same left and right rotations if all digits of strings are equal or it contains the two digits alternatively, and the string length is even. Step 1: Initialize Variables: Initialize the len variable with the string length and ... Read More

Java Program for Closest Prime Number

Mr. Satyabrata
Updated on 02-Jul-2024 09:35:01

2K+ Views

A prime number is a positive integer greater than 1 that is only divisible by 1 and itself. Prime numbers are an essential concept in mathematics and computer science. They are integers that are only divisible by 1 and themselves. Finding prime numbers is an important task in many algorithms, and there are several methods to determine if a number is prime. One such problem is finding the closest prime number to a given number. Problem Statement For a given number find the closest prime number by using Java programming language. Consider the following example - Input ... Read More

How to Read a File into an ArrayList in Java?

Mr. Satyabrata
Updated on 06-Aug-2024 22:54:09

3K+ Views

In Java, an ArrayList is a resizable array, which is implemented as part of the Java Collections Framework. It is a dynamic data structure that can hold any type of objects, including primitive types such as integers and characters. As per the problem statement we have to read a file into an ArrayList. First and foremost we will take the path of the file as input and then we will apply different method to read the file. Let's start!Example For instance Suppose the input file is “myfile.txt”. After reading the content of the file, the result ... Read More

How to Convert Timestamp to Date in Java?

Mr. Satyabrata
Updated on 20-Jun-2024 15:42:32

12K+ Views

In Java, Timestamp can be converted Date by using Date class. Date class is present in java.util package. The constructor of the Date class receives a long value as an argument. Since the constructor of the Date class requires a long value, we need to convert the Timestamp object into a long value using the getTime() method of the TimeStamp class. Let's deep dive into this article, to know how it can be done by using Java programming language. To show you with instance Suppose the timestamp is 06/01/2023. Then corresponding Date is “Fri Jan ... Read More

How to Convert Char to Int in Java?

Mr. Satyabrata
Updated on 17-Aug-2023 17:35:59

1K+ Views

In Java, smaller datatype can be converted to bigger datatype. Here, we will see how to convert char datatype to int datatype. The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65, 535 inclusive). The int data type is a 32-bit signed two's complement integer, which has a minimum value of -231 and a maximum value of 231-1. Let's deep dive into this article, to know how it can be done by using Java programming language. For instance Suppose the given ... Read More

Create a Matrix and Fill Primary Diagonal with 1 and Secondary Diagonal with 2

Mr. Satyabrata
Updated on 17-Aug-2023 17:33:03

392 Views

In Java, a matrix can be represented using a two-dimensional array. Matrices are used for storing and manipulating data that have a tabular structure. Matrices have several properties and operations associated with them, such as addition, subtraction, multiplication, transposition, and determinant calculation. As per the problem statement we have to Create a Matrix and Fill Primary Diagonal with 1 and Secondary Diagonal with 0. Let's start! For instance Suppose we have 4*4 matrix i.e. 4 rows and 4 columns. After performing the operation on matrix, the result will be: Enter the size of the matrix: ... Read More

Java Program to Create a Matrix and Fill it With Palindrome Number

Mr. Satyabrata
Updated on 17-Aug-2023 17:27:34

291 Views

In Java, a matrix can be represented using a two-dimensional array. Matrices are used for storing and manipulating data that have a tabular structure. Matrices have several properties and operations associated with them, such as addition, subtraction, multiplication, transposition, and determinant calculation. As per the problem statement we have to Create a Matrix and Fill it with Palindrome Number. Let's start! For instance Suppose we have 4*5 matrix: After performing the operation on matrix, the result will be: Enter the number of rows: 4 Enter the number of columns: 5 Matrix with Palindrome ... Read More

Java Program to Create a Matrix and Fill it With Armstrong Number

Mr. Satyabrata
Updated on 17-Aug-2023 17:25:59

211 Views

In Java, a matrix can be represented using a two-dimensional array. Matrices are used for storing and manipulating data that have a tabular structure. Matrices have several properties and operations associated with them, such as addition, subtraction, multiplication, transposition, and determinant calculation. As per the problem statement we have to Create a Matrix and Fill it with Armstrong Number. Let's start! For instance Suppose we have 4*3 matrix: After performing the operation on matrix, the result will be: Enter the number of rows: 4 Enter the number of columns: 3 Armstrong Matrix: ... Read More

Previous 1 ... 6 7 8 9 10 ... 918 Next
Advertisements