Вы находитесь на странице: 1из 21

How To List All F 1

How To Set File P 12


Symmetric Matri 123
How To Find Fre 1234
Di erence Betwe 12345
How To Compar 123456
How To Read An 1234567
How To Find Uni
How To Find Sad Java Program :
How To Check H
1 import java.util.Scanner; ?
How To Replace 2
How To Find The 3 public class MainClass
4 {
How To Remove 5 public static void main(String[] args)
Frequently Asked 6 {
7 Scanner sc = new Scanner(System.in);
How To Make Te 8
How To Reverse 9 //Taking rows value from the user
10
10 Prime Numbe 11 System.out.println("How many rows you want in this pattern?");
12
Array Rotation P
13 int rows = sc.nextInt();
Palindrome Prog 14
15 System.out.println("Here is your pattern....!!!");
JDBC 16
Java Practice Coding 17 for (int i = 1; i <= rows; i++)
18 {
File Handling 19 for (int j = 1; j <= i; j++)
x Vs y 20 {
21 System.out.print(j+" ");
Misc... 22 }
23
24 System.out.println();
25 }
26
27 //Close the resources
28
29 sc.close();
30 }
31 }

Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
1
12
123
1234
12345
123456
1234567

Pattern 2 :
1
22
333
4444
55555
666666
7777777

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 //Taking rows value from the user
10
11 System.out.println("How many rows you want in this pattern?");
12
13 int rows = sc.nextInt();
14
15 System.out.println("Here is your pattern....!!!");
16
17 for (int i = 1; i <= rows; i++)
18 {
19 for (int j = 1; j <= i; j++)
20 {
21 System.out.print(i+" ");
22 }
23
24 System.out.println();
25 }
26
27 //Close the resources
28
29 sc.close();
30 }
31 }

Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
1
22
333
4444
55555
666666
7777777

Pattern 3 :
1
12
123
1234
12345
123456
1234567
123456
12345
1234
123
12
1

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 //Taking rows value from the user
10
11 System.out.println("How many rows you want in this pattern?");
12
13 int rows = sc.nextInt();
14
15 System.out.println("Here is your pattern....!!!");
16
17 //Printing upper half of the pattern
18
19 for (int i = 1; i <= rows; i++)
20 {
21 for (int j = 1; j <= i; j++)
22 {
23 System.out.print(j+" ");
24 }
25
26 System.out.println();
27 }
28
29 //Printing lower half of the pattern
30
31 for (int i = rows-1; i >= 1; i--)
32 {
33 for (int j = 1; j <= i; j++)
34 {
35 System.out.print(j+" ");
36 }
37
38 System.out.println();
39 }
40
41 //Closing the resources
42
43 sc.close();
44 }
45 }
Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
1
12
123
1234
12345
123456
1234567
123456
12345
1234
123
12
1

Pattern 4 :
1234567
123456
12345
1234
123
12
1

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 //Taking rows value from the user
10
11 System.out.println("How many rows you want in this pattern?");
12
13 int rows = sc.nextInt();
14
15 System.out.println("Here is your pattern....!!!");
16
17 for (int i = rows; i >= 1; i--)
18 {
19 for (int j = 1; j <= i; j++)
20 {
21 System.out.print(j+" ");
22 }
23
24 System.out.println();
25 }
26
27 //Closing the resources
28
29 sc.close();
30 }
31 }

Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
1234567
123456
12345
1234
123
12
1

[quads id=5]

Pattern 5 :
7654321
765432
76543
7654
765
76
7

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 //Taking rows value from the user
10
11 System.out.println("How many rows you want in this pattern?");
12
13 int rows = sc.nextInt();
14
15 System.out.println("Here is your pattern....!!!");
16
17 for (int i = 1; i <= rows; i++)
18 {
19 for (int j = rows; j >= i; j--)
20 {
21 System.out.print(j+" ");
22 }
23
24 System.out.println();
25 }
26
27 //Closing the resources
28
29 sc.close();
30 }
31 }

Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
7654321
765432
76543
7654
765
76
7

Pattern 6 :
7
76
765
7654
76543
765432
7654321

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 //Taking rows value from the user
10
11 System.out.println("How many rows you want in this pattern?");
12
13 int rows = sc.nextInt();
14
15 System.out.println("Here is your pattern....!!!");
16
17 for (int i = rows; i >= 1; i--)
18 {
19 for (int j = rows; j >= i; j--)
20 {
21 System.out.print(j+" ");
22 }
23
24 System.out.println();
25 }
26
27 //Closing the resources
28
29 sc.close();
30 }
31 }

Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
7
76
765
7654
76543
765432
7654321

Pattern 7 :
7654321
654321
54321
4321
321
21
1

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 //Taking rows value from the user
10
11 System.out.println("How many rows you want in this pattern?");
12
13 int rows = sc.nextInt();
14
15 System.out.println("Here is your pattern....!!!");
16
17 for (int i = rows; i >= 1; i--)
18 {
19 for (int j = i; j >= 1; j--)
20 {
21 System.out.print(j+" ");
22 }
23
24 System.out.println();
25 }
26
27 //Closing the resources
28
29 sc.close();
30 }
31 }

Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
7654321
654321
54321
4321
321
21
1

Pattern 8 :
1234567
123456
12345
1234
123
12
1
12
123
1234
12345
123456
1234567

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 //Taking rows value from the user
10
11 System.out.println("How many rows you want in this pattern?");
12
13 int rows = sc.nextInt();
14
15 System.out.println("Here is your pattern....!!!");
16
17 //Printing upper half of the pattern
18
19 for (int i = rows; i >= 1; i--)
20 {
21 for (int j = 1; j <= i; j++)
22 {
23 System.out.print(j+" ");
24 }
25
26 System.out.println();
27 }
28
29 //Printing lower half of the pattern
30
31 for (int i = 2; i <= rows; i++)
32 {
33 for (int j = 1; j <= i; j++)
34 {
35 System.out.print(j+" ");
36 }
37
38 System.out.println();
39 }
40
41 //Closing the resources
42
43 sc.close();
44 }
45 }

Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
1234567
123456
12345
1234
123
12
1
12
123
1234
12345
123456
1234567

Pattern 9 :
1
121
12321
1234321
123454321
12345654321
1234567654321

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 //Taking rows value from the user
10
11 System.out.println("How many rows you want in this pattern?");
12
13 int rows = sc.nextInt();
14
15 System.out.println("Here is your pattern....!!!");
16
17 for (int i = 1; i <= rows; i++)
18 {
19 //Printing first half of the row
20
21 for (int j = 1; j <= i; j++)
22 {
23 System.out.print(j+" ");
24 }
25
26 //Printing second half of the row
27
28 for (int j = i-1; j >= 1; j--)
29 {
30 System.out.print(j+" ");
31 }
32
33 System.out.println();
34 }
35
36 //Closing the resources
37
38 sc.close();
39 }
40 }

Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
1
121
12321
1234321
123454321
12345654321
1234567654321

Pattern 10 :
1
21
321
4321
54321
654321
7654321

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 //Taking rows value from the user
10
11 System.out.println("How many rows you want in this pattern?");
12
13 int rows = sc.nextInt();
14
15 System.out.println("Here is your pattern....!!!");
16
17 for (int i = 1; i <= rows; i++)
18 {
19 for (int j = i; j >= 1; j--)
20 {
21 System.out.print(j+" ");
22 }
23
24 System.out.println();
25 }
26
27 //Close the resources
28
29 sc.close();
30 }
31 }

Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
1
21
321
4321
54321
654321
7654321

Pattern 11 :
1 1234567 ?
2 234567
3 34567
4 4567
5 567
6 67
7 7
8 67
9 567
10 4567
11 34567
12 234567
13 1234567

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 //Taking rows value from the user
10
11 System.out.println("How many rows you want in this pattern?");
12
13 int rows = sc.nextInt();
14
15 System.out.println("Here is your pattern....!!!");
16
17 //Printing upper half of the pattern
18
19 for (int i = 1; i <= rows; i++)
20 {
21 //Printing i spaces at the beginning of each row
22
23 for (int j = 1; j < i; j++)
24 {
25 System.out.print(" ");
26 }
27
28 //Printing i to rows value at the end of each row
29
30 for (int j = i; j <= rows; j++)
31 {
32 System.out.print(j);
33 }
34
35 System.out.println();
36 }
37
38 //Printing lower half of the pattern
39
40 for (int i = rows-1; i >= 1; i--)
41 {
42 //Printing i spaces at the beginning of each row
43
44 for (int j = 1; j < i; j++)
45 {
46 System.out.print(" ");
47 }
48
49 //Printing i to rows value at the end of each row
50
51 for (int j = i; j <= rows; j++)
52 {
53 System.out.print(j);
54 }
55
56 System.out.println();
57 }
58
59 //Closing the resources
60
61 sc.close();
62 }
63 }

Output :

1 How many rows you want in this pattern? ?


2 7
3 Here is your pattern....!!!
4 1234567
5 234567
6 34567
7 4567
8 567
9 67
10 7
11 67
12 567
13 4567
14 34567
15 234567
16 1234567

Pattern 12 :
1 1 2 3 4 5 6 7 ?
2 2 3 4 5 6 7
3 3 4 5 6 7
4 4 5 6 7
5 5 6 7
6 6 7
7 7
8 6 7
9 5 6 7
10 4 5 6 7
11 3 4 5 6 7
12 2 3 4 5 6 7
13 1 2 3 4 5 6 7

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 //Taking rows value from the user
10
11 System.out.println("How many rows you want in this pattern?");
12
13 int rows = sc.nextInt();
14
15 System.out.println("Here is your pattern....!!!");
16
17 //Printing upper half of the pattern
18
19 for (int i = 1; i <= rows; i++)
20 {
21 //Printing i spaces at the beginning of each row
22
23 for (int j = 1; j < i; j++)
24 {
25 System.out.print(" ");
26 }
27
28 //Printing i to rows value at the end of each row
29
30 for (int j = i; j <= rows; j++)
31 {
32 System.out.print(j+" ");
33 }
34
35 System.out.println();
36 }
37
38 //Printing lower half of the pattern
39
40 for (int i = rows-1; i >= 1; i--)
41 {
42 //Printing i spaces at the beginning of each row
43
44 for (int j = 1; j < i; j++)
45 {
46 System.out.print(" ");
47 }
48
49 //Printing i to rows value at the end of each row
50
51 for (int j = i; j <= rows; j++)
52 {
53 System.out.print(j+" ");
54 }
55
56 System.out.println();
57 }
58
59 //Closing the resources
60
61 sc.close();
62 }
63 }

Output :

1 How many rows you want in this pattern? ?


2 7
3 Here is your pattern....!!!
4 1 2 3 4 5 6 7
5 2 3 4 5 6 7
6 3 4 5 6 7
7 4 5 6 7
8 5 6 7
9 6 7
10 7
11 6 7
12 5 6 7
13 4 5 6 7
14 3 4 5 6 7
15 2 3 4 5 6 7
16 1 2 3 4 5 6 7

Pattern 13 :
1
10
101
1010
10101
101010
1010101

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 System.out.println("How many rows you want in this pattern?");
10
11 int rows = sc.nextInt();
12
13 System.out.println("Here is your pattern....!!!");
14
15 for (int i = 1; i <= rows; i++)
16 {
17 for (int j = 1; j <= i; j++)
18 {
19 if(j%2 == 0)
20 {
21 System.out.print(0);
22 }
23 else
24 {
25 System.out.print(1);
26 }
27 }
28
29 System.out.println();
30 }
31
32 sc.close();
33 }
34 }

Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
1
10
101
1010
10101
101010
1010101

Pattern 14 :
1010101
0101010
1010101
0101010
1010101
0101010
1010101

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 System.out.println("How many rows you want in this pattern?");
10
11 int rows = sc.nextInt();
12
13 System.out.println("Here is your pattern....!!!");
14
15 for (int i = 1; i <= rows; i++)
16 {
17 int num;
18
19 if(i%2 == 0)
20 {
21 num = 0;
22
23 for (int j = 1; j <= rows; j++)
24 {
25 System.out.print(num);
26
27 num = (num == 0)? 1 : 0;
28 }
29 }
30 else
31 {
32 num = 1;
33
34 for (int j = 1; j <= rows; j++)
35 {
36 System.out.print(num);
37
38 num = (num == 0)? 1 : 0;
39 }
40 }
41
42 System.out.println();
43 }
44
45 sc.close();
46 }
47 }

Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
1010101
0101010
1010101
0101010
1010101
0101010
1010101

Pattern 15 :
1111111
1111122
1111333
1114444
1155555
1666666
7777777

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 System.out.println("How many rows you want in this pattern?");
10
11 int rows = sc.nextInt();
12
13 System.out.println("Here is your pattern....!!!");
14
15 for (int i = 1; i <= rows; i++)
16 {
17 for (int j = 1; j <= rows-i; j++)
18 {
19 System.out.print(1);
20 }
21
22 for (int j = 1; j <= i; j++)
23 {
24 System.out.print(i);
25 }
26
27 System.out.println();
28 }
29
30 sc.close();
31 }
32 }

Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
1111111
1111122
1111333
1114444
1155555
1666666
7777777

Pattern 16 :
0000000
0100000
0020000
0003000
0000400
0000050
0000006

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 System.out.println("How many rows you want in this pattern?");
10
11 int rows = sc.nextInt();
12
13 System.out.println("Here is your pattern....!!!");
14
15 for (int i = 0; i < rows; i++)
16 {
17 for (int j = 0; j < rows; j++)
18 {
19 if(i == j)
20 {
21 System.out.print(i);
22 }
23 else
24 {
25 System.out.print(0);
26 }
27 }
28
29 System.out.println();
30 }
31
32 sc.close();
33 }
34 }

Output :

How many rows you want in this pattern?


7
Here is your pattern….!!!
0000000
0100000
0020000
0003000
0000400
0000050
0000006

Pattern 17 :
1
26
3 7 10
4 8 11 13
5 9 12 14 15

Java Program :

1 import java.util.Scanner; ?
2
3 public class MainClass
4 {
5 public static void main(String[] args)
6 {
7 Scanner sc = new Scanner(System.in);
8
9 System.out.println("How many rows you want in this pattern?");
10
11 int rows = sc.nextInt();
12
13 System.out.println("Here is your pattern....!!!");
14
15 for (int i = 1; i <= rows; i++)
16 {
17 int num = i;
18
19 for (int j = 1; j <= i; j++)
20 {
21 System.out.print(num+" ");
22
23 num = num+rows-j;
24 }
25
26 System.out.println();
27 }
28
29 sc.close();
30 }
31 }

Output :

How many rows you want in this pattern?


5
Here is your pattern….!!!
1
26
3 7 10
4 8 11 13
5 9 12 14 15

Pattern 18 :
Di erent Pyramid Pattern Programs In Java

Pattern 19 :
Diamond Pattern Programs In Java

Pattern 20 :
Floyd’s Triangle In Java

Categories Java Interview Programs

 How To Reverse An ArrayList In Java? How To Format Date In Java? 


412 Comments

Faizaan
September 2, 2016 (9:52 pm) #

I had fun playing around with this!

Reply

rajesh
March 16, 2017 (1:50 pm) #

@@@@@@@
@@ @@
@@@@
@ @@ @
@@@
@@@@@@@
can u please write code for this

Reply

Abhishek
April 11, 2017 (5:54 pm) #

void pattern() {
for (int i = 1; i <= 6; i++) {

if (i == 1 || i == 6) {
for (int j = 1; j <= 7; j++) {

System.out.print("@");

}
}

if (i == 2 || i == 3 || i == 4) {
for (int j = 1; j <= 4; j++) {
System.out.print("@");
if (i == 2 && j == 2) {
System.out.print(" ");
}
if (i == 3) {
System.out.print(" ");
}
if ((i == 4) && (j == 1 || j == 3)) {

Вам также может понравиться