Programming Articles - Page 2196 of 3366

How to get the first element of an array in PHP?

AmitDiwan
Updated on 24-Dec-2019 12:17:45

307 Views

To get the first element of an array in PHP, the code is as follows −Example Live DemoOutputThis will produce the following output−Array value ... Value 1 = 150ExampleLet us now see another example − Live DemoOutputThis will produce the following output −Value 1 = 150

How to get random value out of an array in PHP?

AmitDiwan
Updated on 24-Dec-2019 12:15:57

403 Views

To get random value out of an array in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output −Array values ... Value 1 = 150 Value 2 = 100 Value 3 = 120 Value 4 = 110 Value 5 = 115 Value 6 = 103 Value 7 = 105 Value 8 = 125 Random value from arary = 110ExampleLet us now see another example − Live DemoOutputThis will produce the following output−Array values ... Value 1 = 150 Value 2 = 100 Value 3 = 120 Value 4 = 110 Value 5 = 115 Value 6 = 103 Value 7 = 105 Value 8 = 125 Random values from array...150 115

Concatenation of two strings in PHP program

AmitDiwan
Updated on 24-Dec-2019 12:13:08

242 Views

To concatenate two strings in PHP, the code is as follows −Example Live DemoOutputThis will produce the following output−1.967 and 1.969 Both the values are equal!ExampleLet us now see another example − Live DemoOutputThis will produce the following output−First Name = Jack Second Name = Sparrow Concatenation = JackSparrow

Comparing float value in PHP

AmitDiwan
Updated on 24-Dec-2019 12:10:38

768 Views

To compare float values in PHP, the code is as follows −Example Live DemoOutputThis will produce the following output−2.5 3.5 Both the values aren\'t equalExampleLet us now see another example − Live DemoOutputThis will produce the following example−1.967 1.969 Both the values are equal!

‘AND’ vs ‘&&’ operators in PHP

AmitDiwan
Updated on 24-Dec-2019 12:08:08

2K+ Views

The difference is the precedence when we compare AND with && operator. The precedence of AND operator is lower than the operator = when the evaluation is performed, therefore even if both the operators do the same work, the result is different.ExampleLet us first see an example of the AND operator− Live DemoOutputThis will produce the following output−Result = TrueExampleLet us now see an example of the && operator− Live DemoOutputThis will produce the following output:Result = TrueExampleLet us now see the difference in a single example − Live DemoOutputThis will produce the following output−true false

Comparing two dates in PHP

AmitDiwan
Updated on 02-Jan-2020 06:09:34

707 Views

To compare two dates in PHP, the code is as follows. Here, we have used the equality operator to compare dates −Example Live DemoOutputThis will produce the following output−Date1 = 2019-10-30 Date2 = 2019-10-30 Both the dates are equal!ExampleLet us now see another example− Live DemoOutputThis will produce the following output−Date1 = 2019-11-08 Date2 = 2018-08-10 DateOne is the latest date!

How to use method references with Generics in Java?

raja
Updated on 11-Jul-2020 12:25:52

967 Views

The method references are introduced in Java 8 similar to lambda expression. It can allow us to reference methods or constructors without executing them. The method references and lambda expressions require a target type that consists of a compatible functional interface. We can also use a method reference with generic classes and generic methods in java.Exampleinterface MyFunc {    int func(T[] vals, T v); } class MyArrayOps {    static int countMatching(T[] vals, T v) {       int count = 0;       for(int i=0; i < vals.length; i++)          if(vals[i] == v)             count++;       return count;   ... Read More

What is the generic functional interface in Java?

raja
Updated on 11-Jul-2020 12:23:09

4K+ Views

A lambda expression can't specify type parameters, so it's not generic. However, a functional interface associated with lambda expression is generic. In this case, the target type of lambda expression has determined by the type of argument(s) specified when a functional interface reference is declared.Syntaxinterface SomeFunc {  T func(T t); }Exampleinterface MyGeneric {    T compute(T t); } public class LambdaGenericFuncInterfaceTest {    public static void main(String args[]) {       MyGeneric reverse = (str) -> {   // Lambda Expression          String result = "";          for(int i = str.length()-1; i >= 0; i--)           ... Read More

Maximize value of (arr[i] – i) – (arr[j] – j) in an array in C++

Narendra Kumar
Updated on 24-Dec-2019 07:21:26

238 Views

Problem statementGiven an array, arr[] find the maximum value of (arr[i] – i) – (arr[j] – j) where i is not equal to j. Where i and j vary from 0 to n-1 and n is the size of input array arr[].If the input array is {7, 5, 10, 2, 3} then we can obtain 9 maximum value as follows−(element 10 – index 2) - (element 2 – index 3) (10 – 2) – (2 – 3) = 8 – (-1) = 9Algorithm1. Find maximum value of (arr[i] – i) in whole array. 2. Find minimum value of (arr[i] – ... Read More

Maximize the value of the given expression in C++

Narendra Kumar
Updated on 24-Dec-2019 07:17:59

328 Views

Problem statementGiven three non-zero integers a, b and c. The task is to find the maximum value possible by putting addition and multiplication signs between them in any order.Please note that rearrangement of integers is allowed but addition and multiplication sign must be used once.If a = 1, b = 3 and c = 5 then maximum value will be 20 as follows−(1 + 3) * 5 = 20Algorithm1. If all numbers are positive, then add two small numbers and multiply result with larger one 2. If only two numbers are positive, then multiply 2 positive numbers and add remaining ... Read More

Advertisements