freetimestudys@gmail.com          +91-7097633380
  Login Here                        

triangle pattren

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 rows = sc.nextInt();
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
Output :

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 MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows you want");
int rows = sc.nextInt();
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(i+" ");
}
System.out.println();
}
sc.close();
}
}

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

public class Test
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows you want ?");
int rows = sc.nextInt();
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; 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(j+" ");
}
System.out.println();
}
}
}

intput and output

How many rows you want ?
5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

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 rows = sc.nextInt();
for (int i = rows; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}

intput and output

How many rows you want ?
5
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

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 rows = sc.nextInt();

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

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

intput and output

How many rows you want ?
7
7 6 5 4 3 2 1
7 6 5 4 3 2
7 6 5 4 3
7 6 5 4
7 6 5
7 6
7

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 rows = sc.nextInt();  
for (int i = rows; i >= 1; i--)
{
for (int j = rows; j >= i; j--)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}

intput and output

How many rows you want?
5
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1

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 rows = sc.nextInt();
for (int i = rows; i >= 1; i--)
{
for (int j = i; j >= 1; j--)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}

intput and output

How many rows you want ?
5
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1

pattern

import java.util.Scanner;

public classTest
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

System.out.println("How many rows you want?");
int rows = sc.nextInt();
for (int i = rows; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
for (int i = 2; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}

System.out.println();
}
}
}

intput and output

How many rows you want ?
7
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7

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 rows = sc.nextInt();

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

System.out.println();
}
}
}

intput and output

How many rows you want ?
7
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

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 rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");

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

System.out.println();
}
}
}

intput and output

How many rows you want?
7
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
7 6 5 4 3 2 1

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 rows = sc.nextInt();
System.out.println("Here is your 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();
}
}
}

intput and output

How many rows you want ?
7
1234567
234567
34567
4567
567
67
7
67
567
4567
34567
234567
1234567

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 rows = sc.nextInt();
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();
}
}
}

intput and output

How many rows you want?
7
1 2 3 4 5 6 7
2 3 4 5 6 7
3 4 5 6 7
4 5 6 7
5 6 7
6 7
7
6 7
5 6 7
4 5 6 7
3 4 5 6 7
2 3 4 5 6 7
1 2 3 4 5 6 7

pattern

import java.util.Scanner;

public classTest
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);

System.out.println("How many rows you want?");
int rows = sc.nextInt();
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
if(j%2 == 0)
{
System.out.print(0);
}
else
{
System.out.print(1);
}
}
System.out.println();
}
}
}

intput and output

How many rows you want?
7
1
10
101
1010
10101
101010
1010101

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 rows = sc.nextInt();
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= rows-i; j++)
{
System.out.print(1);
}
for (int j = 1; j <= i; j++)
{
System.out.print(i);
}
System.out.println();
}
}
}

intput and output

How many rows you want ?
7
1111111
1111122
1111333
1114444
1155555
1666666
7777777

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 rows = sc.nextInt();
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < rows; j++)
{
if(i == j)
{
System.out.print(i);
}
else
{
System.out.print(0);
}
}
System.out.println();
}
}
}

intput and output

How many rows you want ?
7
0000000
0100000
0020000
0003000
0000400
0000050
0000006

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 rows = sc.nextInt();
for (int i = 1; i <= rows; i++)
{
int num = i;

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

intput and output

How many rows you want ?
5
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15

Diamond 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 YourDiamond?");
int  n= sc.nextInt();
int m = (n)/2;
int row = 1;
System.out.println("Here Is Your Diamond : ");
for (int i = m; i > 0; i--)
{
for (int j = 1; j <= i; j++)
{
System.out.print(" ");
}
for (int j = 1; j <= row; j++)
{
System.out.print("* ");
}
System.out.println(); 
row++;
}
for (int i = 0; i <= m; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(" ");
}
for (int j = row; j > 0; j--)
{
System.out.print("* ");
}
System.out.println();
row--;
}
}
}

intput and output

How Many Rows You Want In ?
7
*
* *
* * *
* * * *
* * *
* *
*