ICSE - JAVA Pattern Programs
JAVA PATTERN PROGRAMS
Pattern - 1
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Source Code:
class Pattern{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
System.out.print(j+" ");
System.out.println();
}
}
}
Pattern - 2
55 4
5 4 3
5 4 3 2
5 4 3 2 1
Source Code:
class Pattern
{
public static void main(String args[])
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=5;j>=i;j--)
System.out.print(j+" ");
System.out.println();
}
}
}
{
public static void main(String args[])
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=5;j>=i;j--)
System.out.print(j+" ");
System.out.println();
}
}
}
Pattern - 3
1 2 3 4 51 2 3 4
1 2 3
1 2
1
5 4 3 2
2 1class Pattern
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=i;j>=1;j--)
System.out.print(j+" ");
System.out.println();
}
class Pattern
{
public static void main(String args[])
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=i;j<=5;j++)
System.out.print(j+" ");
System.out.println();
}
}
class Pattern
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=i;j<=5;j++)
System.out.print(j+" ");
System.out.println();
}
}
class Pattern
{
public static void main(String args[])
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
System.out.print(j+" ");
System.out.println();
}
}
class PatternSource Code:
class Pattern
{
public static void main(String args[])
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
System.out.print(j+" ");
System.out.println();
}
}
}
{
public static void main(String args[])
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
System.out.print(j+" ");
System.out.println();
}
}
}
Pattern - 4
5 4 3 2 15 4 3 2
5 4 3
5 4
5
Source Code:
class Pattern
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
System.out.print(j+" ");
System.out.println();
}
}
}
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
System.out.print(j+" ");
System.out.println();
}
}
}
Pattern - 5
12 1
3 2 1
4 3 2 1
5 4 3 2 1
Source Code:
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=i;j>=1;j--)
System.out.print(j+" ");
System.out.println();
}
}
Pattern - 6
5
4 5 3 4 52 3 4 5 1 2 3 4 5
4 5
Source Code:
{
public static void main(String args[])
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=i;j<=5;j++)
System.out.print(j+" ");
System.out.println();
}
}
}
Pattern - 7
1 2 3 4 5
2 3 4 53 4 5 4 5 5
2 3 4 5
Source Code:
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=i;j<=5;j++)
System.out.print(j+" ");
System.out.println();
}
}
}
Pattern - 8
5 4 3 2 1
4 3 2 13 2 1 2 1 1
4 3 2 1
Source Code:
{
public static void main(String args[])
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
System.out.print(j+" ");
System.out.println();
}
}
}
Pattern - 9
1
2 23 3 3 4 4 4 45 5 5 5 5
2 2
Source Code:
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
System.out.print(i+" ");
System.out.println();
}
}
}
Pattern - 10
5 5 5 5 5
4 4 4 43 3 3 2 21
4 4 4 4
Source Code:
{
public static void main(String args[])
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
System.out.print(i+" ");
System.out.println();
}
}
}
No comments