Java program to Concatenate natural numbers up to given range

Friday, February 4th, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* Write a program to Concatenate natural numbers up to given range using for Loop
   Example:
   Input - 5
   Output - 1 2 3 4 5 */
class Join{
	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);
	}
}
Avatar of surajk

Author Name :
surajk

Total : 0 Comment


Leave a Reply

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup

Email: