Programming Articles

Page 7 of 2545

What is ‘this’ reference in Java?

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

The this is a keyword in Java which is used as a reference to the object of the current class, with in an instance method or a constructor. Using this you can refer the members of a class such as constructors, variables and methods.Using “this” you can −Differentiate the instance variables from local variables if they have same names, within a constructor or a method.class Student {    int age;    Student(int age) {       this.age = age;    } }Call one type of constructor (parametrized constructor or default) from other in a class. It is known as ...

Read More

How to Get a slice of a primitive array in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 979 Views

You can get a part of a Java array in between two specified indexes in various ways.By Copying contents:One way to do so is to create an empty array and copy the contents of the original array from the start index to the endIndex.Exampleimport java.util.Arrays; public class SlicingAnArray {    public static int[] sliceArray(int array[], int startIndex, int endIndex ){       int size = endIndex-startIndex;       int part[] = new int[size];       //Copying the contents of the array       for(int i=0; iarray[i]);       part = stream.toArray();       //Copying the contents of the array       for(int i=0; i

Read More

Reverse Subarray To Maximize Array Value in C++

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

Suppose we have one integer array called nums. The value of this array is defined as the sum of |nums[i]-nums[i+1]| for all i in range 0 to n - 1. Where n is the size of the array. We can select any subarray of the given array and reverse it. We can perform this operation only once. Then we have to find the maximum possible value of the final array.So, if the input is like [1, 5, 4, 2, 3], then the output will be 10.To solve this, we will follow these steps −ret := 0, extra := 0n := ...

Read More

Difference between sums of odd and even digits.

Mahesh Parahar
Mahesh Parahar
Updated on 11-Mar-2026 598 Views

Problem StatementWith a given long integer n, write a program to find the difference between sum of the odd digits and even digits to be 0 or not. Index starts from 0.Examplen = 1212112 Sum of odd position elements = 2 + 2 + 1 = 5 Sum of even position elements = 1 + 1 + 1 + 2 = 5 Difference = 5 - 5 = 0 Output = YesExampleclass JavaTester {    public static int difference(int n){       return (n % 11);    }    public static void main(String args[]){       int n = 1212112;       System.out.println("Number: " + n);       System.out.println(difference(n) == 0 ? "Yes" : "No");       n = 12121121;       System.out.println("Number: " + n);       System.out.println(difference(n) == 0 ? "Yes" : "No");    } }OutputNumber : 1212112 Output: Yes Number : 12121121 Output: No

Read More

How to change the Y-axis title to horizontal using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 4K+ Views

The default direction of Y-axis title using ggplot2 in R is vertical and we can change to horizontal. For this purpose, we can use theme function of ggplot2 package. We would need to use the argument of theme function as axis.title.y=element_text(angle=0)) and this will write the Y-axis title to horizontal but the position will be changed to top.Exampleggplot(df,aes(x))+geom_histogram(bins=30)+theme(axis.title.y=element_text(angle=0))Output

Read More

Difference between sums of odd level and even level nodes of a Binary Tree in Java

Mahesh Parahar
Mahesh Parahar
Updated on 11-Mar-2026 474 Views

Problem StatementWith a given binary tree, write a program to find the difference between sum of nodes at odd level and even level. Assume root at level 1, left/right child of root at level 2 and so on.Example        5       /   \       2     6      /  \     \     1     4    8    /    /  \   3    7    9 Sum of nodes at odd level = 5 + 1 + 4 + 8 = 18 Sum of ...

Read More

Difference between the largest and the smallest primes in an array in Java

Mahesh Parahar
Mahesh Parahar
Updated on 11-Mar-2026 997 Views

Problem StatementWith a given array of integers where all elements are less than 1000000. Find the difference between the largest and the smallest primes in an array.ExampleArray: [ 1, 2, 3, 4, 5 ] Largest Prime Number = 5 Smallest Prime Number = 2 Difference = 5 - 3 = 2.SolutionUse Sieve of Eratosthenes approach, which is an efficient way to find out all prime numbers smaller than a given number. Then we will figure out the largest and smallest prime number to get the required difference.Examplepublic class JavaTester {    static int MAX = 1000000;   ...

Read More

Difference between Traits and Abstract Classes in Scala.

Mahesh Parahar
Mahesh Parahar
Updated on 11-Mar-2026 1K+ Views

TraitsTraits are similar to interfaces in Java and are created using trait keyword.Abstract ClassAbstract Class is similar to abstract classes in Java and are created using abstract keyword.Exampletrait SampleTrait {    // Abstract method    def test    // Non-Abstract method    def tutorials() {       println("Traits tutorials")    } } abstract class SampleAbstractClass {    // Abstract method    def test    // Non-abstract meythod    def tutorials() {       println("Abstract Class tutorial")    } } class Tester extends SampleAbstractClass {    def test() {       println("Welcome to Tutorialspoint") ...

Read More

PHP mt_getrandmax() Function

Malhar Lathkar
Malhar Lathkar
Updated on 11-Mar-2026 210 Views

Definition and UsageThe 'mt' prefix in function's name stands for Mersenne Twister. The mt_ getrandmax() function returns largest integer that can be used in PHP. This function uses Mersenne Twister Random Number Generator method. Value returned by this function serves as the upper limit for mt_rand() function to generate random number.This function always returns an integer.Syntaxmt_getrandmax ( void ) : intParametersSr.NoParameter & Description1This function needs no parametersReturn ValuesPHP mt_getrandmax() function use Mersenne Twister Random Number Generator method. and returns largest possible integer that can be used in PHP. On 64 bit Windows, the number is 2147483647PHP VersionThis function is available ...

Read More

PHP mt_rand() Function

Malhar Lathkar
Malhar Lathkar
Updated on 11-Mar-2026 477 Views

Definition and UsageThe 'mt' prefix in function's name stands for Mersenne Twister. The mt_rand() function returns an integer using Mersenne Twister Random Number Generator method. This function is a drop-in replacement for PHP's rand() function. default range is between 0 and platform specific mt_getrandmax(). On 64 bit Windows OS, it is 2147483647. The mt_rand() function can be called without arguments (in which case the default range will be used) or by specifying min and max parameters.This function always returns an integer.Syntaxmt_rand ( void ) : int mt_rand ( int $min , int $max ) : intParametersSr.NoParameter & Description1minlower limit of ...

Read More
Showing 61–70 of 25,445 articles
« Prev 1 5 6 7 8 9 2545 Next »
Advertisements