# Java program to print pattern of numbers in triangle and reverse trainable form

In this java program, we are implementing a program that will print a trainable in normal and reverse order using numbers.
Submitted by IncludeHelp, on December 05, 2017

Example:

```Input:
Enter number of rows: 10
Output:
Here is your pattern....!!!
1 2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9 10
3 4 5 6 7 8 9 10
4 5 6 7 8 9 10
5 6 7 8 9 10
6 7 8 9 10
7 8 9 10
8 9 10
9 10
10
9 10
8 9 10
7 8 9 10
6 7 8 9 10
5 6 7 8 9 10
4 5 6 7 8 9 10
3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
```

## Program to print triangle in java

```import java.util.Scanner;

public class Pattern14
{
public static void main(String[] args)
{
// create scanner object.
Scanner sc = new Scanner(System.in);

//Taking rows value from the user
System.out.print("Enter rows here : ");
int rows = sc.nextInt();

System.out.println("Here is your pattern....!!!");

//Printing the pattern
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
for (int j = i; j <= rows; j++)
{
System.out.print(j+" ");
}
System.out.println();
}

for (int i = rows-1; i >= 1; i--)
{
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
for (int j = i; j <= rows; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
sc.close();
}
}
```

Output

```Enter rows here : 10
Here is your pattern....!!!
1 2 3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9 10
3 4 5 6 7 8 9 10
4 5 6 7 8 9 10
5 6 7 8 9 10
6 7 8 9 10
7 8 9 10
8 9 10
9 10
10
9 10
8 9 10
7 8 9 10
6 7 8 9 10
5 6 7 8 9 10
4 5 6 7 8 9 10
3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
```

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Top MCQs

ADVERTISEMENT

Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.