Found 9326 Articles for Object Oriented Programming

Java Program to Separate the Individual Characters from a String

Rudradev Das
Updated on 12-Apr-2023 17:40:29

4K+ Views

In the field of computer science, the string is a collection of a continuous character data sets. Here in this particular problem we will use some spaces to execute the logic. The individual characters present here in the string can be accessed through its index to perform the code. Here is a general flow to build a logic code to separate the individual characters from a string in a Java environment. Define a string with characters. Print the individual characters present from a given string. Set an initial to zero. Print the string by using the function string.charAt(i). Iterate ... Read More

Java Program to Sort the Array Elements in Descending Order

Rudradev Das
Updated on 12-Apr-2023 17:29:02

2K+ Views

Array is a collection of same data types stored at some contiguous memory locations. The arrays are a class present in java.until package which provides pre-defined sorting with a static manner and no return value. Here is the syntax of the Arrays.sort() method mentioned below − public static void sort(int[] ar, int from_index, int to_index) Here in the above syntax we have ar - short of the array name from_index - a parameter we can use as optional, where the sorting takes a run. to_index - an optional parameter donates the index of the element. Here is ... Read More

Java Program to Illustrate String Interpolation

Sakshi Ghosh
Updated on 12-Apr-2023 12:34:17

682 Views

String interpolation is a concatenation technique considered to display output text dynamically or effectively by replacing the placeholder characters with variables (or strings in the subsequent examples). String interpolation restructures the code and prevents the need to repeatedly use variables to produce the output. It makes it efficient to write lengthy variable names or text just by replacing the placeholder with the variable names allocated to strings. There are several ways in Java to perform String Interpolation with the help of the concatenation operator and library function or class. Here, we will discuss four different methods of String ... Read More

Java Program to Illustrate Use of Binary Literals

Sakshi Ghosh
Updated on 12-Apr-2023 12:32:32

350 Views

A binary literal is a number that is denoted using binary digits that are 0s and 1s. The values written in data types – byte, int, long, and short can be easily expressed in a binary number system. The prefix 0b or 0B is added to the integer to declare a binary literal. Let us see some examples to understand the topic in a better way. Example The following program displays a value of byte data type to which the value of binary literal is assigned. A class named BinaryLiteral1 is created within which 2-byte data type variables ... Read More

Java Program to Illustrate the usage of Octal Integer

Sakshi Ghosh
Updated on 12-Apr-2023 12:30:06

155 Views

Octal Integer is a number system having a base of 8 and digits from 0 to 7. Int data type is taken into account to store an octal number. The usage of the Octal number system is to be discussed here − Converting decimal to Octal Converting octal to decimal. Conversion from a Decimal number system to an Octal Number system Basics of Conversion To convert any decimal number into its equivalent octal number: Keep dividing the decimal number by the base of the octal number system which is 8 till the quotient 0 is received. Remember ... Read More

Java Program to Sort 2D Array Across Left Diagonal

Rudradev Das
Updated on 13-Apr-2023 11:49:25

438 Views

In the field of data structure, the vector is a growable class array of a particular object. The vector class falls in the legacy class which is fully compatible with the collections. In java.util package, the List interface can use all the methods listed here. Here is the initial capacity is 10 and the general method is − Vector v = new Vector(); The compare() method accepts two parameters and then compare each other by using Java environment logic. Algorithm to sort 2D array across left diagonal Here is the particular algorithm to sort the 2D array across left ... Read More

Java Program to Sort 2D Array Across Columns

Rudradev Das
Updated on 31-May-2024 16:56:36

5K+ Views

In the field of data structure, the vector is a growable class array of a particular object. The vector class falls in the legacy class which is fully compatible with the collections. In java.util package, the List interface can use all the methods listed here. Here is the initial capacity is 10 and the general method is: Vector v = new Vector(); The compare() method accepts two parameters and then compare each other by using Java environment logic. In this article today, we will learn about the sorting process of a 2D array set across the columns. Algorithm to ... Read More

Java Program to Solve Set Cover Problem

Rudradev Das
Updated on 12-Apr-2023 17:12:14

383 Views

The set covering is a well-known NP-hard problem in the combinational optimization technique. We call the set cover problem as NP-Hard, because there is no polynomial real time solution available for this particular problem. There is an algorithm called greedy heuristic is a well-known process for the set cover problem. Here is the example Let U be the universe of elements, {S1, S2, .....Sm} be collection of subsets of the set, U and Cost(S1), C(S2), ......Cost(Sm) be costs of subsets. 1)Let I is the set of elements included so far. Initialize the process I = {} ... Read More

Java Program to Shuffle Vector Elements

Rudradev Das
Updated on 12-Apr-2023 17:06:51

113 Views

Shuffle() is collection class method in Java, works in a random manner based on the permutation logic on a specific group of list elements. Tree are two distinct types of method in a shuffle class(), depending on the particular parameters. Java Collections shuffle(list) Method. Java Collections shuffle(list, random) Method. In this method, we can arrange the characters randomly to generate some random values. Then we will apply the suffle method on it. To perform the vector shuffle, we can use Fisher-Yates shuffle algorithm. In this method, we can learn a linear scan on a vector and swap each ... Read More

Java Program to Show Time By Rolling Through Hours and Months

Rudradev Das
Updated on 12-Apr-2023 17:04:57

54 Views

The credibility of an efficient coding language depends upon how well it can manage the date and time. In a Java Virtual Environment we get some inbuilt facilities like date, time and calendar to handle the problem related to date and time. java. until date class - In Java, there are many contains those are very important for the program. Date class deals with the operation about the date and time. They are those type of classes which comes with the feature of cloneable, Serializable and comparable interfaces. Extract the current date and time - There are two types ... Read More

Advertisements