Server Side Programming Articles - Page 1637 of 2650

Sum of the series Kn + ( K(n-1) * (K-1)1 ) + ( K(n-2) * (K-1)2 ) + ... (K-1)n in C++

sudhir sharma
Updated on 17-Aug-2020 10:22:15

333 Views

In the problem, we are ginen two number k and n of the series K^n + ( K^(n-1) * (K-1)^1 ) + ( K^(n-2) * (K-1)^2 ) + ... (K-1)^n. Our task is to create a program to find the sum of the series.Let’s take an example to understand the problem, Input: n = 3, k = 4 Output: 175 Explanation: Sum of the series is = 4^3 + ( (4^2)*(3^1) ) + ( (4^1)*(3^2) ) + ( (4^0)*(3^3) ) = 64 + 48 + 36 + 27 = 175A simple way to solve the problem, is using a for ... Read More

Sum of XOR of all subarrays in C++

sudhir sharma
Updated on 17-Aug-2020 10:14:33

1K+ Views

In this problem, we are given an array arr[] of n numbers. Our task is to create a program to find the sum of XOR of all subarrays of the array.Here, we need to find all sub-arrays of the given array, and then for each subarray, we will find the xor of element and add the XOR value to the sum variable.Let’s take an example to understand the problem, Input: arr[] = {5, 1, 4} Output: Explanation: XOR of all subarrays for the array : XOR {5} = 5 XOR {1} = 1 XOR {4} = 4 XOR {5, 1} ... Read More

Sum of XOR of all possible subsets in C++

sudhir sharma
Updated on 17-Aug-2020 10:00:52

431 Views

In this problem, we are given an array aar[] of n numbers. Our task is to create a program to find the Sum of XOR of all possible subsets.Here, we will find all subsets of the array. Then for each subset, we will find the XOR of elements of the subset and add them to the sum variable.Let’s take an example to understand the problem, Input: arr[] = {5, 1, 4} Output: 20 Explanation: XOR of all subsets: {5} = 5 {1} = 1 {4} = 4 {5, 1} = 4 {5, 4} = 1 {1, 4} = 5 {5, ... Read More

Sum of XOR of all pairs in an array in C++

sudhir sharma
Updated on 17-Aug-2020 09:58:43

2K+ Views

In this problem, we are given an array arr[] of n integers. Our task is to create a program to find the sum of XOR of all pairs in an array.Let’s take an example to understand the problem, Input: arr[] = {5, 1, 4} Output: 10 Explanation: the sum of all pairs: 5 ^ 1 = 4 1 ^ 4 = 5 5 ^ 4 = 1 sum = 4 + 5 + 1 = 10One simple approach to solve this problem is to run nested loops and find all pairs of numbers. Find XOR of each pair and add ... Read More

File Objects in Java

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

1K+ Views

The File object represents the actual file/directory on the disk. Here are the list of constructors to create File Object in Java −Sr.No.Method & Description1File(File parent, String child)This constructor creates a new File instance from a parent abstract pathname and a child pathname string.2File(String pathname)This constructor creates a new File instance by converting the given pathname string into an abstract pathname.3File(String parent, String child)This constructor creates a new File instance from a parent pathname string and a child pathname string.4File(URI uri)This constructor creates a new File instance by converting the given file: URI into an abstract pathname.Assuming an object is ... Read More

Precision Handling in Java

AmitDiwan
Updated on 17-Aug-2020 09:46:45

573 Views

Let us see how precisions are handled in Java −Example Live Demoimport java.io.*; import java.lang.*; public class Demo{    public static void main(String[] args){       double my_val = 34.909;       System.out.println("The formatted value of 34.909 is ");       System.out.println(String.format("%.7f", my_val));       double my_val_2 = 12.56;       System.out.println("The formatted value of 12.56 is ");       System.out.println(String.format("%.9f", my_val_2));    } }OutputThe formatted value of 34.909 is 34.9090000 The formatted value of 12.56 is 12.560000000A class named Demo contains the main function, where a double valued integer is declared, and it is ... Read More

Logical Operators on String in Java

AmitDiwan
Updated on 17-Aug-2020 09:45:22

669 Views

Let us implement logical operators on String in Java −Example Live Demoimport java.io.*; public class Demo{    public static void main(String[] args){       int a = 45, b = 32, c = 87, d = 1;       System.out.println("The first variable is " + a);       System.out.println("The second variable is = " + b);       System.out.println("The third variable is = " + c);       if ((a > b) && (b == c)){          d = a + b + c;          System.out.println("The sum is " + ... Read More

Sum of upper triangle and lower triangle in C++

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

1K+ Views

In this problem, we are given a matrix. Our task is to create a program to print the sum of upper triangle and lower triangle.Lower triangleM00                     0             0       …        0 M10                     M11               0       …        0 M20                     M21               M22      …     ... Read More

Complex Numbers in Java

AmitDiwan
Updated on 17-Aug-2020 09:43:26

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.Example Live Demopublic 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;       ... Read More

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

AmitDiwan
Updated on 17-Aug-2020 09:41:23

1K+ Views

To check if a string is a valid keyword in Java, the code is as follows −Example Live Demoimport 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)

Advertisements