Found 33676 Articles for Programming

Type Erasure in Java

AmitDiwan
Updated on 17-Aug-2020 08:59:55

171 Views

To support generic programming, as well as perform a stricter type check, Java implements type erasure.All type parameters in generic types are replaced with the bound (if unbounded) or object type. This way, the bytecode will only contain classes, methods, and interfaces.Type casts to preserve the type.Bridge methods are generated so as to preserve the polymorphism concept in extended generic types.Example Live Demoimport java.io.PrintStream; import java.util.*; public class Demo{    public Demo(){    }    public static void main(String args[]){       List my_list = new ArrayList();       my_list.add("Hi there");       String my_str;       ... Read More

Maximum given sized rectangles that can be cut out of a sheet of paper in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:53:52

428 Views

We are given the dimensions of the sheet of paper, it’s Length L, and Breadth B. Also, we are given the dimensions of a small rectangle, it’s length l, and breadth b. The goal is to find the maximum number of smaller rectangles that can be cut out of a sheet of paper.We will do following steps −Firstly, we will take horizontal alignment, lengths L and l of sheet and rectangle respectively. Start aligning the L by l and B by b and count the rectangles.Then also do the same in vertical alignments. Count again. Return the maximum value of ... Read More

Maximum length of subarray such that sum of the subarray is even in C++

Sunidhi Bansal
Updated on 17-Aug-2020 08:52:38

922 Views

We are given with an array Arr[] of integers. The goal is to find longest length subarray of Arr[] , sum of whose elements is even. That is, the sum of elements of a subarray is even and that subarray is longest in length.Input − Arr[] = { 2, 3, 5, 2, 6, 7 }.Output −Maximum length of subarray − 4Explanation −The maximum length subarray is { 5, 2, 6, 7 }. Sum is 20 which is even.Input − Arr[] = { 5, 7, 7, 3, 4 }.Output − Maximum length of subarray − 4Explanation − The maximum length subarray ... Read More

Shuffle or Randomize a list in Java

AmitDiwan
Updated on 17-Aug-2020 08:56:23

299 Views

To shuffle a list in Java, the code is as follows −Example Live Demoimport java.util.*; public class Demo{    public static void main(String[] args){       ArrayList my_list = new ArrayList();       my_list.add("Hello");       my_list.add(", ");       my_list.add("this");       my_list.add("is");       my_list.add("a");       my_list.add("sample");       System.out.println("The original list is : " + my_list);       Collections.shuffle(my_list);       System.out.println(" The shuffled list is : " + my_list);    } }OutputThe original list is : [Hello, ,, this, is, a, sample] The shuffled list is ... Read More

Maximum number of candies that can be bought in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:50:11

833 Views

We are given an array of candies[] of length stored in ‘size’. Each element candies[i] has a number for candies of type i.The goal is to buy as many candies as possible for any amount of money. The conditions are as given −If you purchase X[i] of type i (0

What is the maximum possible value of an integer in Java ?

AmitDiwan
Updated on 17-Aug-2020 08:50:41

3K+ Views

The MAX_VALUE is used to find the maximum possible value for an integer in Java. Let us see an example −Example Live Demopublic class Demo{    public static void main(String[] args){       System.out.println("The type is");       System.out.println(Integer.TYPE);       System.out.println("The size is");       System.out.println(Integer.SIZE);       System.out.println("The max value of integer is");       System.out.println(Integer.MAX_VALUE);    } }OutputThe type is int The size is 32 The max value of integer is 2147483647A class named Demo uses the Integer class and gives the various characteristics of the Integer class such as type, size ... Read More

Maximum number of 2×2 squares that can be fit inside a right isosceles triangle in C

Sunidhi Bansal
Updated on 17-Aug-2020 08:48:50

786 Views

We are given a right isosceles triangle. Isosceles triangle is the one which has two sides of equal length. Right triangle is the one which has height(ag in fig.) and base (dg in fig.) perpendicular to each other. The goal is to find the maximum number of squares that can fit into this right isosceles triangle of side 2 sq units. The sides base or height (both equal) are taken as input. No. of squares is output.Refer to the below figure to understand the problemThe given triangle of height ag and base gd has 3 squares of side 2 each. ... Read More

Maximum no. of contiguous Prime Numbers in an array in C++

Sunidhi Bansal
Updated on 17-Aug-2020 08:46:30

488 Views

We are given with an array of prime numbers, arranged in random order. The size of the array is N. The goal is to find the longest sequence of contiguous prime numbers in the array.Prime number is the one which has only two factors, 1 and the number itself. 1, 2, 3, 5, 7, 11, 13….are prime numbers whereas 4, 6, 8, 9, 10….20 are non-prime. Every non-prime number has more than 2 factors. Let’s understand with examples.Input − Arr[] = { 1, 3, 5, 2, 6, 7, 13, 4, 9, 10Output − 3Explanation − The prime numbers in the ... Read More

Maximum consecutive repeating character in string in C++

Sunidhi Bansal
Updated on 17-Aug-2020 08:44:50

2K+ Views

We are given a string of alphabets. The task is to find the character which has the longest consecutive repetitions occurring in string. Let’s understand with examples.Input− String[] = “abbbabbbbcdd”Output − bExplanation − In the above string, the longest consecutive sequence is of character ‘b’. Count of consecutive b’s is 4.Input− String[] = “aabbcdeeeeed”Output − bExplanation − In the above string, the longest consecutive sequence is of character ‘e’. Count of consecutive e’s is 5.Approach used in the below program is as followsThe character array string1[] is used to store the string of alphabets.Function maxRepeating(char str[], int n) takes two ... Read More

Maximum consecutive one’s (or zeros) in a binary circular array in C++

Sunidhi Bansal
Updated on 17-Aug-2020 08:43:21

776 Views

We are given with a circular array. Circular array is the array for which we consider the case that the first element comes next to the last element. It is used to implement queues. So we have to count the maximum no. of consecutive 1’s or 0’s in that array.Let’s understand with examples.Input − Arr[] = { 1, 1, 0, 1, 0, 1, 0, 1, 1, 1 }Output − Maximum consecutive 1’s are 5. Or Maximum consecutive 0’s is 1.Explanation − From Arr[] index 7 to 9 and then indexes 0 and 1. 1’s are 5. No consecutive 0’s but ... Read More

Advertisements