Question 1: Write a program that prints the numbers from 1 to 100 on separate lines. But for multiples of three print “Foo” instead of the number and for the multiples of five print “Bar”. For numbers which are multiples of both three and five print “FooBar”.

public class FooBar {                     

        public static void main(String[] args) {

        //To be completed

        }

}

Question 2: Write a recursive method that takes a String as a parameter and returns a new string which is its reverse.

public class ReverseString {

        public static void main(String[] args){        

            System.out.println("Hello reversed =" + reverse("Hello"));

            System.out.println("Radar reversed =" + reverse("Radar"));

            System.out.println("This is backward reversed =" + reverse("This is backward"));

        }

        public static String reverse(String s){

                //To be completed

        }

}

Question 3: Given an unsorted array of integers, print the longest non-decreasing sequence and its length. For example, given [100, 4, 200, 1, 3, 9, 2, 23, 22], your method should print “The longest consecutive elements sequence is  [1, 3, 9] and its length is 3”.

public class LongestNonDecSeq {

        public static void main(String[] args) {

                int [] test1 = {1,3,5,6,7,9};

                int [] test2 = {100, 4, 200, 1, 3, 9, 2, 23, 22};

                longest(test1);

                longest(test2);

        }

        private static void longest(int[] a) {

                // To be Completed

        }

}