Java program – String concatenation example

by Nideesh C on April 28, 2011 · 0 comments

in Java Programming




public class Ruler {
    public static void main(String[] args) {
        String ruler1 = "1";
        String ruler2 = ruler1 + " 2 " + ruler1;
        String ruler3 = ruler2 + " 3 " + ruler2;
        String ruler4 = ruler3 + " 4 " + ruler3;
        String ruler5 = ruler4 + " 5 " + ruler4;

        System.out.println(ruler1);
        System.out.println(ruler2);
        System.out.println(ruler3);
        System.out.println(ruler4);
        System.out.println(ruler5);
    }

}


/*************************************************************************
 *  Execution:    java Ruler
 *
 *  Prints the relative lengths of the subdivisions on a ruler.
 *
 *  % java Ruler
 *  1
 *  1 2 1
 *  1 2 1 3 1 2 1
 *  1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
 *  1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1
 *
 *************************************************************************/



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C Program to accepts two strings and compare them. Finally it prints whether both are equal, or first string is greater than the second or the first string is less than the second string
  2. C program to read a string and check whether it is a palindrome or not (without using library functions). Output the given string along with suitable message.
  3. C Program to accept two strings and concatenate them i.e.The second string is appended to the end of the first string
  4. C program to read two strings and concatenate them (without using library functions). Output the concatenated string along with the given string
  5. C program to accept a string and find the sum of all digits present in the string

Leave a Comment

Previous post:

Next post: