freetimestudys@gmail.com          +91-7097633380
  Login Here                        

pattern

import java.util.Scanner;

public class Test
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How Many Rows You Want?");
int noOfRows = sc.nextInt();
int rowCount = 1;
for (int i = noOfRows; i > 0; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(" ");
}
for (int j = 1; j <= rowCount; j++)
{
System.out.print(rowCount+" ");
}
System.out.println();
rowCount++;
}
}
}

intput and output

How Many Rows You Want ?
5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

pattern

import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How Many Rows You Want In Your Pyramid?");
int noOfRows = sc.nextInt();
int rowCount = 1;
System.out.println("Here Is Your Pyramid");
for (int i = noOfRows; i > 0; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(" ");
}
for (int j = 1; j <= rowCount; j++)
{
System.out.print(j+" ");
}

System.out.println();
rowCount++;
}
}
}

intput and output

How Many Rows You Want?
5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

pattern

import java.util.Scanner;
public class Test
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How Many Rows You Want?");
int noOfRows = sc.nextInt();
int rowCount = 1;
for (int i = noOfRows; i > 0; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(" ");
}
for (int j = 1; j <= rowCount; j++)
{
System.out.print("* ");
}
System.out.println();
rowCount++;
}
}
}

intput and output

How Many Rows You Want ?
9
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *

pattern

import java.util.Scanner;
public class Test 
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How Many Rows You Want ?");
int noOfRows = sc.nextInt();
int rowCount = 1;
for (int i = noOfRows; i > 0; i--)
{
for (int j = 1; j <= i*2; j++)
{
System.out.print(" ");
}
for (int j = 1; j <= rowCount; j++)
{
System.out.print(j+" ");
}
for (int j = rowCount-1; j >= 1; j--)
{
System.out.print(j+" ");
}
System.out.println();
rowCount++;
}
}
}

intput and output

How Many Rows You Want ?
9
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 6 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1

pattern

import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How Many Rows You Want ?");
int noOfRows = sc.nextInt();
int rowCount = noOfRows;
System.out.println("Here Is Your Pyramid");
for (int i = 0; i < noOfRows; i++)
{
for (int j = 1; j <= i*2; j++)
{
System.out.print(" ");
}
for (int j = 1; j <= rowCount; j++)
{
System.out.print(j+" ");
}
for (int j = rowCount-1; j >= 1; j--)
{
System.out.print(j+" ");
}
System.out.println();
rowCount--;
}
}
}

intput and output

How Many Rows You Want ?
9
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 6 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1

pattern

import java.util.Scanner;

public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How Many Rows You Want In Your Pyramid?");
int noOfRows = sc.nextInt();
int rowCount = 1;
for (int i = noOfRows; i >= 1; i--)
{
for (int j = 1; j <= i*2; j++)
{
System.out.print(" ");
}
for (int j = i; j <= noOfRows; j++)
{
System.out.print(j+" ");
}
for (int j = noOfRows-1; j >= i; j--)
{
System.out.print(j+" ");
}
System.out.println();
rowCount++;
}
}
}

intput and output

How Many Rows You Want?
9
9
8 9 8
7 8 9 8 7
6 7 8 9 8 7 6
5 6 7 8 9 8 7 6 5
3 4 5 6 7 8 9 8 7 6 5 4 3
2 3 4 5 6 7 8 9 8 7 6 5 4 3 2
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1