Friday, August 16, 2013

Java Program 005

Write a program DisplayPattern1.java, which accepts int value as arguments and print the Following Output:
Ex: Input: 12
Output: 
1   2   3   4
5   6   7   8
9  10  11 12


// Author : J. Srivastav Reddy
// Date : 30-7-2013

public class DisplayPattern1
{ public static void main(String[] args)
{ int endValue = Integer.parseInt(args[0]);
int j = 1;
int temp = 1;

for(int i = 1;j <= endValue;i++)
{
for(;j <= temp + 3;j++)
System.out.print(j + " ");
temp = j;

System.out.println("");
}
}
}

No comments:

Post a Comment