Computer Science, asked by SharanyaN, 6 months ago

What are the types of casting shown in the following examples?

double p= 12.3:

inta= 14

1. Long b = a; ii. int 4 = (int)p:​

Answers

Answered by kvimalkumar79
0

Answer:

meetgooglecom/xis-frgx-bnw

Answered by shreyachoudhari1971
1

Explanation:

Write a generic method to count the number of elements in a collection that have a specific property (for example, odd integers, prime numbers, palindromes).

Answer:

public final class Algorithm {

public static <T> int countIf(Collection<T> c, UnaryPredicate<T> p) {

int count = 0;

for (T elem : c)

if (p.test(elem))

++count;

return count;

}

}

where the generic UnaryPredicate interface is defined as follows:

public interface UnaryPredicate<T> {

public boolean test(T obj);

}

For example, the following program counts the number of odd integers in an integer list:

import java.util.*;

class OddPredicate implements UnaryPredicate<Integer> {

public boolean test(Integer i) { return i % 2 != 0; }

}

public class Test {

public static void main(String[] args) {

Collection<Integer> ci = Arrays.asList(1, 2, 3, 4);

int count = Algorithm.countIf(ci, new OddPredicate());

System.out.println("Number of odd integers = " + count);

}

}plz follow

Similar questions