Server Side Programming Articles - Page 1639 of 2646

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

Sunidhi Bansal
Updated on 17-Aug-2020 09:10:45

202 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

What are C++ features missing in Java?

AmitDiwan
Updated on 17-Aug-2020 09:20:06

1K+ Views

There are many features that can be seen in C++ but not in Java. A few of them have been listed below −No unsigned int option in JavaNo destructor in Java as well as ‘delete’ since garbage collector performs this operation for it.No friend classes or friend functions in Java.There are no pointers in Java.There is no typedef option in Java.Since Java is a purely object oriented language, there are no global variables or global functions.The concept of templates present in C++ can’t be found in Java.The ‘::’ scope resolution operator is not there, since there is no question of ... Read More

Maximum number of groups of size 3 containing two type of items in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:09:27

222 Views

Given the task is to calculate the maximum number of groups of size 3 that can be formed when N number of items of type A and M number of items of type B are given.Also, each group should have at least one item of each type, that is either A or B.Let’s now understand what we have to do using an example −Input − N=3, M=5Input − 2ExplanationGroup 1: 1 item of type A and 2 items of type B Group 2: 1 item of type A and 2 items of type B In total, 2 items of type ... Read More

Examples of soft references and phantom references?

AmitDiwan
Updated on 17-Aug-2020 09:17:59

323 Views

Soft references are often used to implement memory-sensitive caches. Let us see an example of soft references in Java −Example Live Demoimport java.lang.ref.SoftReference; class Demo{    public void display_msg(){       System.out.println("Hello there");    } } public class Demo_example{    public static void main(String[] args){       Demo my_instance = new Demo();       my_instance.display_msg();       SoftReference my_softref = new SoftReference(my_instance);       my_instance = null;       my_instance = my_softref.get();       my_instance.display_msg();    } }OutputHello there Hello thereA class named Demo contains a function named ‘display_msg’, that displays the relevant ... Read More

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

Sunidhi Bansal
Updated on 17-Aug-2020 09:07:36

196 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

Unreachable statement using the non-final variable in Java

AmitDiwan
Updated on 17-Aug-2020 09:06:35

168 Views

Following is an example, wherein we will see unreachable statement using the non-final variable −Exampleclass Demo_example {    int a = 2, b = 3;    void display_msg(){       while (a < b){          System.out.println("The first variable is greater than the second");       }       System.out.println("This is an unreachable statement");    } } public class Demo{    public static void main(String args[]){       Demo_example my_instance = new Demo_example();       my_instance.display_msg();    } }Output“The first variable is greater than the second” displayed infinitelyA class named Demo_example, that defines ... Read More

Sum of the series 2^0 + 2^1 + 2^2 +...+ 2^n in C++

sudhir sharma
Updated on 17-Aug-2020 09:17:02

1K+ Views

In this problem, we are given a number n which defines the n-th term of the series 2^0, 2^1, 2^2, …, 2^n. Our task is to create a program to find the sum of the series 2^0 + 2^1 + 2^2 +...+ 2^n.Let’s take an example to understand the problem, Inputn=6Output Explanation sum = 2^0 + 2^1 + 2^2 + 2^3 + 2^4 + 2^5 + 2^6 sum = 1 + 2 + 4 + 8 + 16 + 32 + 64 = 127A simple solution to the problem is by using the loop. Finding the 2^i, for each value from 0 ... Read More

Maximize number of continuous Automorphic numbers in C++

Sunidhi Bansal
Updated on 17-Aug-2020 09:05:49

332 Views

Given the task is to maximize the number of continuous Automorphic elements in a given array with N number of elements.An automorphic number is a number whose square ends with the same digits as the number itself. For example 5 is an automorphic number as 5*5 = 25 and 25 ends with 5.Let’s now understand what we have to do using an example −Input − arr[]={5, 3, 625, 6, 8, 1}Output − 2Explanation − Automorphic numbers present in the above array are 5, 625, 6 and 1 but the maximum continuous automorphic numbers are {625, 6} which makes the output ... Read More

Unreachable statement using final variable in Java

AmitDiwan
Updated on 17-Aug-2020 09:04:48

229 Views

Unreachable statements are those that don’t get executed when the code is being executed. This could be so because −There is a return statement before the code.There is an infinite loop in the code.The execution of the code is terminated forcibly before it executes.Here, we will see how the unreachable statement can be used with the ‘final’ keyword −Example Live Democlass Demo_example{    final int a = 56, b = 99;    void func_sample(){       while (a < b){          System.out.println("The first value is less than the second.");       }       System.out.println("This ... Read More

Types of References in Java

AmitDiwan
Updated on 17-Aug-2020 09:02:34

914 Views

There are four different kinds of references based on the way in which the data is garbage collected.Strong referencesWeak referencesSoft referencesPhantom referencesStrong referenceIt is the default type of reference object. An object that has active strong reference can’t be garbage collected. It is possible only if the variable that is strongly referenced points to null. Let us see an example −Exampleclass Demo {    //Some functionality } public class Demo_example{    public static void main(String[] args){       Demo my_inst = new Demo();       my_inst = null;    } }Weak referenceThey are not default class of reference ... Read More

Advertisements