Contents: Click for quick access
31. Write a program to display following pattern. 1111111 1111122 1111333 1114444 1155555 1666666 7777777 , 32. Write a program to display following pattern. 1010101 0101010 1010101 0101010 1010101 0101010 1010101 ,33. Write a program to display following pattern . 1 2 6 3 7 10 4 8 11 13 5 9 12 14 15 , 34. Write a program to display following pattern. 1 2 3 4 5 6 7 2 3 4 5 6 7 1 3 4 5 6 7 1 2 4 5 6 7 1 2 3 5 6 7 1 2 3 4 6 7 1 2 3 4 5 7 1 2 3 4 5 6 ,35. Write a program to display following pattern. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 , 36. Write a program to display following pattern . 1 2 13 3 12 14 4 11 15 22 5 10 16 21 23 6 9 17 20 24 27 7 8 18 19 25 26 28 , 37. Write a program to display following pattern . 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1 ,38. Write a program to display following pattern. 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 , 39. Write a program to display following pattern. 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 ,40. Write a program to display following pattern. 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 ,
I’ve included a list of some of the Java programs below. You may also view all of the Java programs on our mobile app. I strongly advise you to use our mobile app for a better experience.
31. Write a program to display following pattern.
1111111
1111122
1111333
1114444
1155555
1666666
7777777 ,
import java.util.Scanner;
public class Pattern
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows do you want this pattern to have?");
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();
}
sc.close();
}
}
32. Write a program to display following pattern.
1010101
0101010
1010101
0101010
1010101
0101010
1010101 ,
import java.util.Scanner;
public class Pattern
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows do you want this pattern to have?");
int rows = sc.nextInt();
for (int i = 1; i < = rows; i++)
{
int num;
if(i%2 == 0)
{
num = 0;
for (int j = 1; j < = rows; j++)
{
System.out.print(num);
num = (num == 0)? 1 : 0;
}
}
else
{
num = 1;
for (int j = 1; j < = rows; j++)
{
System.out.print(num);
num = (num == 0)? 1 : 0;
}
}
System.out.println();
}
sc.close();
}
}
33. Write a program to display following pattern .
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15 ,
import java.util.Scanner;
public class Pattern
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows do you want this pattern to have?");
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();
}
sc.close();
}
}
34. Write a program to display following pattern.
1 2 3 4 5 6 7
2 3 4 5 6 7 1
3 4 5 6 7 1 2
4 5 6 7 1 2 3
5 6 7 1 2 3 4
6 7 1 2 3 4 5
7 1 2 3 4 5 6 ,
import java.util.Scanner;
public class Pattern
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows do you want this pattern to have?");
int rows = sc.nextInt();
for(int i=1;i< rows+1 ;i++)
{
for(int j=i; j < rows+1 ;j++)
{
System.out.print(j + " ");
}
for(int k=1; k < i ;k++)
{
System.out.print(k + " ");
}
System.out.println();
}
sc.close();
}
}
35. Write a program to display following pattern.
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15 ,
import java.util.Scanner;
public class Pattern
{
public static void main(String[] args)
{
System.out.println("How many rows do you want this pattern to have?");
Scanner sc = new Scanner(System.in);
int rows = sc.nextInt();
int value = 1;
for (int i = 1; i < = rows; i++)
{
for (int j = 1; j < = i; j++)
{
System.out.print(value+"\t");
value++;
}
System.out.println();
}
}
}
36. Write a program to display following pattern .
1
2 13
3 12 14
4 11 15 22
5 10 16 21 23
6 9 17 20 24 27
7 8 18 19 25 26 28 ,
import java.util.Scanner;
public class Pattern
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("How many rows do you want this pattern to have?");
int rows = sc.nextInt();
for(int i=1 ; i < = rows ; i++)
{
System.out.print(i + " ");
int n = i;
for(int j = 1; j < i ; j++)
{
if(j%2 != 0)
{
System.out.print((n + ((2 * (rows + 1 - i)) - 1)) + " ");
n = n + ((2 * (rows + 1 - i)) - 1);
}
else
{
System.out.print((n + 2 * (i - j)) + " ");
n = n + 2 * (i - j);
}
}
System.out.println();
}
sc.close();
}
}
37. Write a program to display following pattern .
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1 ,
import java.util.Scanner;
public class Pattern
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("How many rows do you want this pattern to have?");
int rows = scanner.nextInt();
for (int i = rows; i >= 1; i--)
{
for (int j = i; j >= 1; j--)
{
System.out.print(j + " ");
}
System.out.println();
}
for (int i = 1; i < = rows; i++)
{
for (int j = i; j >= 1; j--)
{
System.out.print(j + " ");
}
System.out.println();
}
}
}
38. Write a program to display following pattern.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1 ,
import java.util.Scanner;
public class Pattern
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("How many rows do you want this pattern to have?");
int rows = scanner.nextInt();
for (int i = 1; i < = rows; i++)
{
for (int j = rows; j > i; j--)
{
System.out.print(" ");
}
int temp = 1;
for (int k = 1; k < = i; k++)
{
System.out.print(temp + " ");
temp = temp * (i - k) / (k);
}
System.out.println();
}
}
}
39. Write a program to display following pattern.
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1 ,
import java.util.Scanner;
public class Pattern
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("How many rows do you want this pattern to have?");
int rows = scanner.nextInt();
for (int i = 1; i < = rows; i++)
{
for (int j = 1; j < i; j++)
{
System.out.print(" ");
}
for (int k = 1; k < = rows - i + 1; k++)
{
System.out.print(k + " ");
}
System.out.println();
}
}
}
40. Write a program to display following pattern.
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 ,
import java.util.Scanner;
public class Pattern
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("How many rows do you want this pattern to have?");
int rows = scanner.nextInt();
for (int i = 1; i < = rows; i++)
{
for (int j = rows; j > i; j--)
{
System.out.print(" ");
}
for (int k = 1; k < = i; k++)
{
System.out.print(k + " ");
}
System.out.println();
}
for (int i = 1; i < = rows; i++)
{
for (int j = 1; j < = i; j++)
{
System.out.print(" ");
}
for (int k = 1; k < = rows - i; k++)
{
System.out.print(k + " ");
}
System.out.println();
}
}
}