# Java program to print number star half diamond pattern type 3

## Print number star half diamond pattern type 3

Take input from user i.e number of lines required (N value).Take two loops one for each line (say ‘i’) and other for each digit in a particular line (say ‘j’). i starts from 1 and j starts from 1.The program is divided into two sections for decrement part (i.e first 4 lines) and increment part (last 4 lines). Two separate i and j loops are written for each part. In first part i is from n to 1 and in the second part i is from 1 to n.Here ‘i’ loop is used to access each line from 1 to n and ‘j’ loop is used to print values in each line. j loop is executed until it reaches i value.Print ‘i’ value until the j loop reaches i value.Print the final value ‘i’ of each line and go to next line.

## Algorithm

• Take input from user i.e number of lines required (N value).
• Take two loops one for each line (say ‘i’) and other for each digit in a particular line (say ‘j’). i starts from 1 and j starts from 1.
• The program is divided into two sections for decrement part (i.e first 4 lines) and increment part (last 4 lines). Two separate i and j loops are written for each part. In first part i is from n to 1 and in the second part i is from 1 to n.
• Here ‘i’ loop is used to access each line from 1 to n and ‘j’ loop is used to print values in each line. j loop is executed until it reaches i value.
• Print ‘i’ value until the j loop reaches i value.
• Print the final value ‘i’ of each line and go to next line.

## Code in Java

```import java.io.*;
class PrepInsta {
public static void main(String[] args) throws IOException {
int n, i, j;
System.out.print("Enter N value:");
for (i = n; i >= 1; i--) {
for (j = 1; j < i; j++) {
System.out.print(i + "*");
}
System.out.println(i);
}
for (i = 1; i <= n; i++) {
for (j = 1; j < i; j++) {
System.out.print(i + "*");
}
System.out.println(i);
}
}
}
This code is contributed by Shubham Nigam (Prepinsta Placement Cell Student)
```