Programming Articles

Page 1498 of 2547

Check if a given number is Pronic in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 965 Views

Here we will see, how to check whether a number is Pronic number or not. A number that can be arranged to form a rectangle, are called the pronic numbers. First few pronic numbers are: 0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342. The pronin numbers are product of two consecutive integers. So a pronic number n = x * (x + 1).Here we will check and generate some pronic numbers.Example#include #include using namespace std; bool isPronicNumber(int num) {    for (int i = 0; i

Read More

Sort an array of strings according to string lengths in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Here we will see how to sort a list of strings based on their lengths. So if a string has less number of characters, then that will be placed first, then other longer strings will be placed. Suppose the strings arestr_list = {“Hello”, “ABC”, “Programming”, “Length”, “Population”}after sorting, they will be −str_list = {“ABC”, “Hello”, “Length”, “Population”, “Programming”}Here we will create our own comparison logic to sort them. That comparison logic will be used in the sort function in C++ STL.Algorithmcompare(str1, str2): Begin    if length of str1 < length of str2, then       return 1    return ...

Read More

The set() method of AbstractList class in Java

Daniol Thomas
Daniol Thomas
Updated on 11-Mar-2026 149 Views

The set() method of the AbstractList class is used to replace the element at the specified position in this list with the specified element. It returns the element that gets replaced.The syntax is as follows:public E set(int index, E ele)Here, the parameter index is the index of the element to replace, whereas ele is the element to be stored at the specified position.To work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to implement set() method of the AbstractlList class in Java:Exampleimport java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) ...

Read More

Can I overload private methods in Java?

Narasimha Murthi
Narasimha Murthi
Updated on 11-Mar-2026 2K+ Views

Overloading is a one of the mechanisms to achieve polymorphism where, a class contains two methods with same name and different parameters.Whenever you call this method the method body will be bound with the method call based on the parameters.Overloading private methodsYes, we can overload private methods in Java but, you can access these from the same class.Examplepublic class Calculator {    private int addition(int a , int b){       int result = a+b;       return result;    }    private int addition(int a , int b, int c){       int result = a+b+c; ...

Read More

Get file extension name in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 752 Views

The file extension is the suffix that is attached to the computer file and it denotes the format of the file. A program that demonstrates getting the file extension name is given as follows −Exampleimport java.io.File; public class Demo {    private static String fileExtension(File file) {       String name = file.getName();       if(name.lastIndexOf(".") != -1 && name.lastIndexOf(".") != 0)          return name.substring(name.lastIndexOf(".") + 1);       else          return "";    }    public static void main(String[] args) {       File file = new File("demo1.txt");   ...

Read More

IntStream peek() method in Java

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 793 Views

The peek() method in the IntStream class in Java returns a stream consisting of the elements of this stream. It additionally performs the provided action on each element as elements are consumed from the resulting stream.The syntax is as followsIntStream peek(IntConsumer action)Here, the parameter action is a non-interfering action to perform on the elements as they are consumed from the stream. The IntConsumer represents an operation that accepts a single int-valued argument and returns no result.The following is an example to implement IntStream peek() method in JavaExampleimport java.util.*; import java.util.stream.IntStream; public class Demo { public static void ...

Read More

The contains() method of Java AbstractCollection class

Daniol Thomas
Daniol Thomas
Updated on 11-Mar-2026 186 Views

The contains() method of the AbstractCollection class checks whether an element is in the AbstractCollection or not. It returns a Boolean i.e. TRUE if the element is in the collection, else FALSE is returned.The syntax is as follows:public boolean contains(Object ele)Here, ele is the element to be checked for existence.To work with AbstractCollection class in Java, import the following package:import java.util.AbstractCollection;The following is an example to implement AbstractCollection contains() method in Java:Exampleimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection = new ArrayList();       absCollection.add("Football");     ...

Read More

C++ Program to Implement Johnson's Algorithm

Nishtha Thakur
Nishtha Thakur
Updated on 11-Mar-2026 2K+ Views

Here we will see the Johnson’s Algorithm to find shortest path between two vertices. The graph is given here. The shortest path between the edges is like below. This program will take the number of vertices, number of edges, and the edges with their costs.Input − Vertices: 3Edges: 5Edge with costs −1 2 82 1 121 3 223 1 62 3 4Output − The distance matrix of the graph.081210046140AlgorithmjohnsonAlgorithm(cost)Input − The cost matrix of given Graph.Output − Matrix to for shortest path between any vertex to any vertex.Begin    Create another matrix ‘A’ same as cost matrix, if there is no ...

Read More

The contains() method of AbstractSequentialList in Java

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 186 Views

The contains() method of AbstractSequentialList in Java is used to check whether an element is in the Collection.The syntax is as followspublic boolean contains(Object ob)Here, ob is the element to be checked. To work with the AbstractSequentialList class in Java, you need to import the following packageimport java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList contains() method in JavaExampleimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo { public static void main(String[] args) { AbstractSequentialList absSequential = new LinkedList(); absSequential.add(250); absSequential.add(320); ...

Read More

How to stop C++ console application from exiting immediately?

Anvi Jain
Anvi Jain
Updated on 11-Mar-2026 1K+ Views

Sometimes we have noticed that the console is being closed immediately after displaying the result. So we cannot see the result properly. Here we will see how we can stop the console from closing.The idea is very simple. We can use the getchar() function at the end. This will wait for one character. If one character is pressed, the console will exit.Example#include using namespace std; int main() {    cout

Read More
Showing 14971–14980 of 25,466 articles
Advertisements