Server Side Programming Articles

Page 1249 of 2109

Maximum number of dots after throwing a dice N times in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 234 Views

Given the task is to calculate the maximum number of dots that can be expected after throwing a dice N times having M faces.The first face of the dice contains 1 dot, the second face has 2 dots and so on. Likewise the M-th face contains M number of dots.The probability of appearance of each face becomes 1/M.Let’s now understand what we have to do using an example −Input − M=2, N=3Output − 1.875Explanation − The dice has 2 sides = {1, 2}If the dice is thrown 3 times then the sample space will be = MN = 23{(1, 1, ...

Read More

Maximum number of ones in a N*N matrix with given constraints in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 256 Views

Given the task is to find the maximum number of ones in a binary matrix possible with the following constraints.Two integers N and X are given where X

Read More

Maximum number of segments of lengths a, b and c in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 359 Views

Given the task is to find the maximum number of line segments of lengths a, b and c that can be formed from given positive integer N.Let’s now understand what we have to do using an example −Input − N=8, a=3, b=1, c=2Output − 8Explanation − N can be divided into 8 segments of b which is maximum number of segments that can be made.Input − N=13, a=2, b=7, c=3Output − 6Approach used in the below program as followsIn function MaxSegment() declare an array MaxSeg[N +1] of type int and initialize it with value -1.The put the zero-th index equal ...

Read More

Product of all prime numbers in an Array in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 356 Views

Given an integer array arr[] with some elements, the task is to find the product of all the prime number of that numbers.Prime number are those number which are either divided by 1 or the number itself, or a prime number is a number which is not divisible by any other number except 1 and the number itself. Like 1, 2, 3, 5, 7, 11, etc.we have to find the solution for the given array −Input −arr[] = { 11, 20, 31, 4, 5, 6, 70 }Output − 1705Explanation − Prime numbers in array are − 11, 31, 5 their ...

Read More

Maximum number of unique prime factors in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 1K+ Views

Given the task is to find the maximum number of unique prime factors a number can have in the range of [1, N] where N is given.Let’s now understand what we have to do using an example −Input − N=100Output − 3Explanation − Let us take 30 in the range of [1, 100]30 = 3 * 2 * 5 = unique prime factors. Therefore, in the range of [1, 100] a maximum of 3 unique factors can be found.Input − N=300Output − 4Approach used in the below program as followsIn function MaxPrime() we will first check if (N < 2). ...

Read More

Verification in Java (JVM)

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 793 Views

Once the byte code is loaded by the JVM, (with the help of the .class file), the bytecode is checked to see the validity with the help of the verifier. The verifier checks the linking so as to perform operations efficiently. This way, the interpreter performs much efficiently. This process is known as verification.Examplepublic class Demo{    private float my_val;    float my_function(int my_val){       int balance = my_val;       this.my_val += balance;       return this.my_val;    }    public static void main(String[] args){       Demo my_obj = new Demo();     ...

Read More

Reasons for a C++ program crash

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 1K+ Views

The abnormal behavior of C++ programs often leads to program crash. You may have encountered problems like Segmentation fault, Aborted, Floating point exception etc. Following are sample programs that may help you to understand the reasons for a C++ program crash.ExceptionsExceptions in C++ are responses of a program when it encounters an abnormal condition. The program crashes due to such exceptions if they are not handled properly using try-catch blocks. Following program crashes due to divide by zero exception −Example#include int main(){    int num1=10;    int num2=0;    int quotient=num1/num2;    printf(" Quotient is: %d", quotient);    return ...

Read More

Object Graph in Java Serialization

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 911 Views

An object graph contains a set of objects that are automatically serialized given that the object that contains the reference is serialized too. Any object that is serialized and contains an object reference, the object reference will be serialized by the JVM.Exampleimport java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; class One implements Serializable{    Two s2 = new Two(); } class Two implements Serializable{    Three s3 = new Three(); } class Three implements Serializable{    int i = 34;    int j = 67; } public class Demo_Serialize{    public static void main(String args[]) throws Exception{   ...

Read More

How to check if a string is a valid keyword in Java?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

To check if a string is a valid keyword in Java, the code is as follows −Exampleimport java.util.*; public class Demo{    static boolean valid_identifier(String my_str, int n){       if (!((my_str.charAt(0) >= 'a' && my_str.charAt(0) = 'A' && my_str.charAt(1) = 'a' && my_str.charAt(i) = 'A' && my_str.charAt(i) = '0' && my_str.charAt(i)

Read More

Complex Numbers in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 7K+ Views

Complex numbers are those that have an imaginary part and a real part associated with it. They can be added and subtracted like regular numbers. The real parts and imaginary parts are respectively added or subtracted or even multiplied and divided.Examplepublic class Demo{    double my_real;    double my_imag;    public Demo(double my_real, double my_imag){       this.my_real = my_real;       this.my_imag = my_imag;    }    public static void main(String[] args){       Demo n1 = new Demo(76.8, 24.0),       n2 = new Demo(65.9, 11.23),       temp;       temp ...

Read More
Showing 12481–12490 of 21,090 articles
Advertisements