Programming Articles - Page 2483 of 3366

C/C++ Program for the Triangular Matchstick Number?

sudhir sharma
Updated on 19-Aug-2019 07:33:21

228 Views

A triangle that is made by using matchsticks arrange to make an equilateral triangle, this is called the triangular matchstick number. Triangular matchstick number is the number of matchsticks required to make the matchstick triangle.In this problem, we have the number is the floor of a matchstick pyramid, X. and our task is to write a program to print the total minimum number of matchstick required to form a pyramid of matchsticks of x floors.Let's look at an example that will make the concept more clear, Input: 7 Output: 84ExplanationThis is an extension of triangular numbers. For integer X, the ... Read More

C/C++ Program for the Odd-Even Sort (Brick Sort)?

sudhir sharma
Updated on 19-Aug-2019 07:26:35

514 Views

The odd-even sword also known as the brick sort is a similar sorting technique, like bubble sort. This sorting technique is subdivided into 2 phases odd phase and even phase, Both these phases simultaneously at every iteration until all the elements get sorted.The Odd phase of this programming technique works as a bubble sort but only on the elements that have an odd index.Similarly, the even phase works only on the elements that have an even index.For making this concept more clear let's take an example :Input: a[]={3, 5, 7, 6, 1, 4, 2} Output: 1 2 3 4 5 ... Read More

C/C++ Program for Number of solutions to Modular Equations?

sudhir sharma
Updated on 19-Aug-2019 07:17:42

153 Views

We have an n number of coins and we have to French the coin way that it makeup Pyramid of maximum height. We will arrange the first coin in First row second and third coin in the second row and so onIn the given diagram, we make pyramid 6 of coins having a height of 3. We cannot make height 4 but we will need 10 coins. It is simple to get the height by using this formula;H = {(-1+ √(1+8N))/2}Input: n = 10 Output: Height of pyramid: 4ExplanationHeight by using this formulaH = {(-1+ √(1+8N))/2}Example#include #include using ... Read More

C/C++ Program for Finding the vertex, focus and directrix of the parabola?

sudhir sharma
Updated on 19-Aug-2019 07:14:05

409 Views

A set of points on a plain surface that forms a curve such that any point on that curve is equidistant from a point in the center (called focus) is a parabola.The general equation for the parabola isy = ax2 + bx + cThe vertex of a parabola is the coordinate from which it takes the sharpest turn whereas a is the straight-line used to generate the curve.Focus is the point with is equidistant from all points of the parabola.Here, we will find the vertex, focus, and directrix of a parabola. There is a mathematical formula that finds all these ... Read More

How to detect the value change of a JSlider in Java?

raja
Updated on 12-Feb-2020 05:32:30

1K+ Views

A JSlider is a subclass of JComponent class and it is similar to scroll bar which allows the user to select a numeric value from a specified range of integer values. A JSlider has a knob which can slide on a range of values and can be used to select a particular value. and it can generate a ChangeListener interface.We can detect the value changed when the slider is moved horizontally using the Graphics2D class and override paint() method.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class ValueChangeJSliderTest extends JFrame {    private JSlider slider;    public ValueChangeJSliderTest() { ... Read More

How to read the data from a CSV file in Java?

raja
Updated on 01-Jul-2020 12:10:16

24K+ Views

A CSV stands for Comma Separated Values. In a CSV file, each line contains words that are separated with a comma(, ) and it is stored with a .csv extension.We can read a CSV file line by line using the readLine() method of BufferedReader class. Split each line on comma character to get the words of the line into an array. Now we can easily print the contents of the array by iterating over it or by using an appropriate index.CSV FileExampleimport java.io.*; public class CSVReaderTest {    public static final String delimiter = ", ";    public static void read(String csvFile) {   ... Read More

How can we print all the capital letters of a given string in Java?

Vivek Verma
Updated on 14-May-2025 11:57:53

6K+ Views

The Character class is a subclass of the Object class, and it wraps a value of the primitive type char in an object. An object of type Character class contains a single field whose type is char. We can print all the capital letters of a given string using the following approaches - Using isUpperCase() Method Using ASCII Comparison Using isUpperCase() Method The isUpperCase() is the method of the Character class. It accepts a character as a parameter and returns true if it is an uppercase letter and false if not.To ... Read More

How can we implement a custom iterable in Java?

raja
Updated on 23-Nov-2023 11:23:04

2K+ Views

An Iterable interface is defined in java.lang package and introduced with Java 5 version. An object that implements this interface allows it to be the target of the "for-each" statement. This for-each loop is used for iterating over arrays and collections. An Iterable interface can also be implemented to create custom behavior. Syntax public interface Iterable Example import static java.lang.String.format; import java.util.*; // Person class class Person { private String firstName, lastName; private int age; public Person(){ } public Person(String firstName, String lastName, int age) { this.firstName = firstName; ... Read More

Importance of return type in Java?

Vivek Verma
Updated on 29-May-2025 15:48:02

26K+ Views

A method in Java is a set of statements that can be reused in the program whenever we want. We can write a method once and call it multiple times. We can return values from a method; the datatype of the value we return is known as the return type.  We return values from a Java method using a return statement. A return statement causes the program control to transfer back to the caller of a method. Every method in Java is declared with a return type, ... Read More

Addition of two number using ‘-‘ operator?

sudhir sharma
Updated on 16-Aug-2019 12:05:43

3K+ Views

Operator overloading is an important concept in C++. It is a type of polymorphism in which an operator is overloaded to give user-defined meaning to it. The overloaded operator is used to perform the operation on the user-defined data type. For example, '+' operator can be overloaded to perform addition on various data types, like for Integer, String(concatenation), etc.Input10 20 20 30Output30 50ExplanationTo perform addition of two numbers using ‘-‘ operator by Operator overloading. Binary operators will require one object as an argument so they can perform the operation. If we are using Friend functions here then it will need ... Read More

Advertisements