Java Program to Print V Numbers Pattern

Write a Java program to print V numbers pattern using for loop.

package Shapes4;

import java.util.Scanner;

public class VNumber1 {

	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter V Shape Number Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing the V Shape Number Pattern");
		
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= i; j++ ) 
			{
				System.out.print(j);
			}
			for (int k = 1; k <= 2 * (rows - i); k++ ) 
			{
				System.out.print(" ");
			}
			for (int l = i; l >= 1; l-- ) 
			{
				System.out.print(l);
			}
			System.out.println();
		}
	}
}
Java Program to Print V Numbers Pattern

This Java program prints the alphabetical V pattern of numbers using a while loop.

package Shapes4;

import java.util.Scanner;

public class VNumber2 {

	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter V Shape Number Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing the V Shape Number Pattern");
		int i, j, k, l;
		i = 1 ; 
		
		while (i <= rows ) 
		{
			j = 1 ; 
			while (j <= i ) 
			{
				System.out.print(j);
				j++;
			}
			k = 1; 
			while (k <= 2 * (rows - i)) 
			{
				System.out.print(" ");
				k++;
			}
			l = i; 
			while(l >= 1 ) 
			{
				System.out.print(l);
				 l--;
			}
			System.out.println();
			i++;
		}
	}
}
Enter V Shape Number Pattern Rows = 8
Printing the V Shape Number Pattern
1              1
12            21
123          321
1234        4321
12345      54321
123456    654321
1234567  7654321
1234567887654321

This Java example uses the do while loop to display the capital V pattern of numbers.

package Shapes4;

import java.util.Scanner;

public class VNumber3 {

	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter V Shape Number Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing the V Shape Number Pattern");
		int i, j, k, l;
		
		i = 1 ;
		do 
		{
			j = 1 ;
			do
			{
				System.out.print(j);
				
			} while( ++j <= i );
			
			k = 1 ;
			while(k <= 2 * (rows - i))
			{
				System.out.print(" ");
				k++;
			}
			
			l = i; 
			do
			{
				System.out.print(l);

			} while(--l >= 1 );
			
			System.out.println();

		}while(++i <= rows);
	}
}
Enter V Shape Number Pattern Rows = 9
Printing the V Shape Number Pattern
1                1
12              21
123            321
1234          4321
12345        54321
123456      654321
1234567    7654321
12345678  87654321
123456789987654321