rss
Twitter Delicious Facebook Digg Stumbleupon Favorites

Saturday, October 8, 2011

A program to Concatenate string

In computer programming, string concatenation is the operation of joining two character strings end-to-end. For example, the strings "snow" and "ball" may be concatenated to give "snowball". In many programming languages, string concatenation is a binary infix operator.
For example, the following expression uses the "+" symbol as the concatenation operator to join 2 strings: "Hello, " + "World";, and has the value "Hello, World".
In computer science, in particular in the theory of computation, the concatenation operation on strings is generalized to an operation on sets of strings as follows:
For two sets of strings S1 and S2, the concatenation S1S2 consists of all strings of the form vw where v is a string from S1 and w is a string from S2.
In this definition, the string vw is the ordinary concatenation of strings v and w as defined in the introductory section. In this context, sets of strings are often referred to as formal languages. Notice that we do not use an explicit operator symbol for representing the concatenation.
One of the principles of relational database design is that the fields of data tables should reflect a single characteristic of the table's subject, which means that they should not contain concatenated strings. When concatenation is desired in a report, it should be provided at the time of running the report. For example, to display the physical address of a certain customer, the data might include building number, street name, building subunit number, city name, state/province name, postal code, and country name, e.g., "123 Fake St Apt 4, Boulder, CO 80302, USA", which combines 7 fields. However, the customers data table should not use one field to store that concatenated string; rather, the concatenation of the 7 fields should happen upon running the report. The reason for such principles is that without them, the entry and updating of large volumes of data becomes error-prone and labor-intensive. Separately entering the city, state, ZIP code, and nation allows data-entry validation (such as detecting an invalid state abbreviation). Then those separate items can be used for sorting or indexing the records, such as all with "Boulder" as the city name.

class Concatenate{
      public static void main(String args[]){
      int num = Integer.parseInt(args[0]);
      String result = " ";
      for(int i=1;i<=num;i++){
           result = result + i + " ";
      }
      System.out.println(result);
  }
}

0 comments:

Post a Comment

Powered by Blogger.