Programming Articles - Page 2003 of 3366

Explain difference between == and is operator in Python.

Mahesh Parahar
Updated on 15-Apr-2020 08:24:35

325 Views

== operator== operator compares the operands by checking the equality of values of objects.is operatoris operator compares the operands by checking the objects to be the same or not.ExampleFollowing is the program in Python to showcase the difference. Live Demolist1 = [1] list2 = [1] list3 = list1 print(id(list1)) print(id(list2)) if (list1 == list2):    print("True") else:    print("False") if (list1 is list2):    print("True") else:    print("False") if (list1 is list3):    print("True") else:    print("False")Output140380664377096 140380664376904 True False True

Difference between two given time periods in C++

Mahesh Parahar
Updated on 15-Apr-2020 08:18:24

464 Views

Problem StatementGiven two time periods in the string 'HH:MM: SS' format. Here 'HH' represents hours, 'MM' represents minutes and 'SS' represents seconds. Find the difference in the same string format between these two time periods.Time period 1 = 8:6:2 Time period 2 = 3:9:3 Time Difference is 4:56:59ExampleFollowing is the program in C++ to find the required output. Live Demo#include using namespace std; int main() {    int hour1, minute1, second1;    int hour2, minute2, second2;    int diff_hour, diff_minute, diff_second;    cout minute1 >> second1;    cout minute2 >> second2;    if(second2 > second1) {     ... Read More

Difference between Traits and Abstract Classes in Scala.

Mahesh Parahar
Updated on 16-May-2020 11:33:34

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.Example Live DemoFollowing is the program in Scala to show the usage of Traits and Abstract Classes.trait 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")    } } ... Read More

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

Mahesh Parahar
Updated on 16-May-2020 11:29:51

962 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.Example Live DemoFollowing is the program in Java to find the required output.public ... Read More

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

Mahesh Parahar
Updated on 16-May-2020 14:54:17

235 Views

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

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

Mahesh Parahar
Updated on 16-May-2020 14:50:36

420 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 sums of odd and even digits.

Mahesh Parahar
Updated on 16-May-2020 14:49:21

566 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 = YesExample Live DemoFollowing is the program in Java to find the required output.class JavaTester {    public static int difference(int n){       return (n % ... Read More

Difference between sum of the squares of and square of sum first n natural numbers.

Mahesh Parahar
Updated on 16-May-2020 14:45:24

979 Views

Problem StatementWith a given number n, write a program to find the difference between sum of the squares of and square of sum first n natural numbers.Examplen = 3 Squares of first three numbers = 3x3 + 2x2 + 1x1 = 9 + 4 + 1 = 14 Squares of sum of first three numbers = (3 + 2 + 1)x(3 + 2 + 1) = 6x6 = 36 Difference = 36 - 14 = 22Example Live DemoFollowing is the program in Java to find the required difference.public class JavaTester {    public static int difference(int n){   ... Read More

Explain difference between Strong Entity and Weak Entity

Mahesh Parahar
Updated on 16-May-2020 14:36:04

15K+ Views

Strong EntityStrong Entity is independent to any other entity in the schema. A strong entity always have a primary key. In ER diagram, a strong entity is represented by rectangle. Relationship between two strong entities is represented by a diamond. A set of strong entities is known as strong entity set.Weak EntityWeak entity is dependent on strong entity and cannot exists without a corresponding strong. It has a foreign key which relates it to a strong entity. A weak entity is represented by double rectangle. Relationship between a strong entity and a weak entity is represented by double diamond. The ... Read More

Difference between out and ref keyword in C#

Mahesh Parahar
Updated on 16-May-2020 14:16:00

19K+ Views

out keywordout keyword is used to pass arguments to method as a reference type and is primary used when a method has to return multiple values. ref keyword is also used to pass arguments to method as reference type and is used when existing variable is to be modified in a method. Following is the valid usage of ref and out keywords in C#.Example Live Demousing System.IO; using System; public class Program {    public static void update(out int a){       a = 10;    }    public static void change(ref int d){       d = 11; ... Read More

Advertisements