Check if Binary Representation is Palindrome in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

833 Views

Here we use different python inbuilt function. First we use bin() for converting number into it’s binary for, then reverse the binary form of string and compare with originals, if match then palindrome otherwise not. Example Input: 5 Output: palindrome Explanation Binary representation of 5 is 101 Reverse it and result is 101, then compare and its match with originals. So its palindrome Algorithm Palindromenumber(n) /* n is the number */ Step 1: input n Step 2: convert n into binary form. Step 3: skip the first two characters of a string. Step 4: them reverse the ... Read More

Python Boolean Operations

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

439 Views

The basic Boolean operations are and, or, not operations. The and operation − The basic syntax of and operation is: x and y. It indicates that when the x is false, then return x, otherwise returns y. The or operation −The basic syntax of or operation is: x or y. It indicates that when the x is false, then return y, otherwise returns x. The not operation − The basic syntax of and operation is: not x. It indicates that when the x is false, then it returns true, otherwise it returns false. Example Code Live ... Read More

Math Class Methods in Java Programming

Arushi
Updated on 30-Jul-2019 22:30:23

502 Views

The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. Class Declaration Following is the declaration for java.lang.Math class − public final class Math extends Object Field Following are the fields for java.lang.Math class − static double E − This is the double value that is closer than any other to e, the base of the natural logarithms. static double PI − This is the double value that is closer than any other to pi, the ratio of the circumference of a circle ... Read More

Covariance and Contravariance in C#

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

301 Views

To deal with classes effectively, use the concept of covariance and contra variance. Let us consider the following as our class. One is a base class for class Two, whereas Two is a base class for Three. class One { } class Two: One { } class Three : Two { } A base class can hold a derived class, but the opposite is not possible. With Covariance, you can pass a derived type where a base type is expected. Co-variance can be used on array, interface, delegates, etc in C#. Contra variance is for parameters. ... Read More

Make Your Collections Thread-Safe in C#

Prabhas
Updated on 30-Jul-2019 22:30:23

398 Views

The .NET Framework 4 brought the System.Collections.Concurrent namespace. This has several collection classes that are thread-safe and scalable. These collections are called concurrent collections because they can be accessed by multiple threads at a time. The following concurrent collection types use lightweight synchronization mechanisms: SpinLock, SpinWait, etc. These are new in .NET Framework 4. Let us see the concurrent collection in C# − Type Description BlockingCollection Bounding and blocking functionality for any type. ConcurrentDictionary Thread-safe implementation of a dictionary of key-value pairs. ConcurrentQueue Thread-safe implementation of a FIFO (first-in, first-out) queue. ConcurrentStack Thread-safe ... Read More

Print 2D Array or Matrix in Java Programming

Arushi
Updated on 30-Jul-2019 22:30:23

1K+ Views

In this post we will try to print an array or matrix of numbers at console in same manner as we generally write on paper. For this the logic is to access each element of array one by one and make them print separated by a space and when row get to emd in matrix then we will also change the row Example Live Demo public class Print2DArray { public static void main(String[] args) { final int[][] matrix = { ... Read More

PriorityQueue Class in Java Programming

Rishi Raj
Updated on 30-Jul-2019 22:30:23

169 Views

The java.util.PriorityQueue class is an unbounded priority queue based on a priority heap.Following are the important points about PriorityQueue − The elements of the priority queue are ordered according to their natural ordering, or by a Comparator provided at queue construction time, depending on which constructor is used. A priority queue does not permit null elements. A priority queue relying on natural ordering also does not permit insertion of non-comparable objects. Class declaration Following is the declaration for java.util.PriorityQueue class − public class PriorityQueue extends AbstractQueue implements Serializable Parameters Following ... Read More

Compile Unsafe Code in C#

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

3K+ Views

For compiling unsafe code, you have to specify the /unsafe command-line switch with command-line compiler. For example, to compile a program named one.cs containing unsafe code, from command line, give the command − csc /unsafe one.cs Under Visual Studio IDE, enable use of unsafe code in the project properties. The following are the steps − Open Project properties by double clicking the properties node in the Solution Explorer. Click on the “Build” tab. Select the option "Allow unsafe code".

Python Text Sequence Types

Chandu yadav
Updated on 30-Jul-2019 22:30:23

803 Views

In python the str object, handles the text or string type data. Strings are immutable. The strings are sequence of Unicode characters. We can use single quote, double quotes or triple quotes to define the string literals. ‘This is a string with single quote’ “Another Text with double quotes” ‘’’Text using three single quotes’’’ or “””Text using three double quotes””” We can use triple quotes to assign multiline strings in python. There is different string related functions. Some of the String methods are as follows − Sr.No. Operation/Functions & Description 1 s.capitalize() Convert first ... Read More

Private Constructors and Singleton Classes in Java Programming

Rishi Raj
Updated on 30-Jul-2019 22:30:23

2K+ Views

As we know the primary role of the constructor is to instantiate a class object now if we made the constructor as private then we restrict its calling to be only in defining a class and not in some other class. Now the singleton class in Java is defined as the class which restricts the instantiation of a class and ensure that only one instance of the class exists in the JVM. After first time if instantiate the singleton class the new variable also points to the first instance created. In order to create a singleton class we could use ... Read More

Advertisements