Sort by

recency

|

296 Discussions

|

  • + 0 comments

    What is the point of the code saying "read from STDIN" when the data needs to be hardcoded?

  • + 0 comments
    public class Solution {
        static void printArray(Object[] arr) {
            for (Object o : arr) {
                System.out.println(o.toString());
            }
        }
    
        public static void main(String[] args) {
            Object[] arr = {1, 2, 3, "Hello", "World"};
            
            printArray(arr);
        }
    }
    
  • + 0 comments

    This is a great exercise to understand the power of Java generics! Funinexchange Login

  • + 0 comments

    Yeah, the key here is to use a generic method instead of overloading—something like public static void printArray(T[] array) will handle both integers and strings. I learned that the simple approach often saves time, kind of like when I used rapidtestmedellin for quick and confidential health testing—it just worked smoothly without extra complications.

  • + 0 comments

    Giving 0 star to this qus.

    public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            List<Integer> arInt = new ArrayList<>();
            arInt.add(1);
            arInt.add(2);
            arInt.add(3);
            
            List<String> arStr = new ArrayList<>();
            arStr.add("Hello");
            arStr.add("World");
            printArray(arInt);
            printArray(arStr);
        }
        
        public static<T> void printArray(List<T> o){
            o.forEach(a -> System.out.println(a.toString()));
        }