Work Sheet No. 2

Do the following Problems.
  1. Write a Java Program to calculate the sum of elements in an array. Assume that elements are already in an array.
  2. Write a Java Program to sort an array.
  3. A simple way of encoding a message is the railfence cypher. In this scheme, we first make a string from the original by extracting all of the characters in the odd positions and then append the string we get from the original's even-index characters. For example, in the string "FOOLEDYOUDIDNTI", we have the odd position characters "OLDODDT" and the even position characters "FOEYUINI" (the first character, "F", is considered an even position character because it is at position zero). Concatenating these character sets gives the encoded string "OLDODDTFOEYUINI".

    Write a application that takes as a command line argument a single string. The application should apply the railfence cypher on the argument and should print the results of the transformation.

    For example, if your application is called RailFenceCypher, then you should be able to enter:

       $ java RailFenceCypher "This is a test of the emergency broadcast system"
    
    The output of your program should be:
       hsi  eto h mrec racs ytmTi sats fteeegnybodatsse