Skip to content

Commit 418f8f9

Browse files
committed
Pattern 10
1 parent b968af3 commit 418f8f9

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

EncryptionDecryption/bin/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/snippet/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package snippet;
2+
3+
public class Snippet {
4+
Divisors are
5+
}
6+

InterviewPrograms/src/com/java/basic/Divisors.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import java.util.ArrayList;
44
import java.util.Collections;
5+
import java.util.HashSet;
56
import java.util.Scanner;
7+
import java.util.TreeSet;
68

79
/*
810
* Divisors of N
@@ -25,7 +27,7 @@ public static void main(String[] args) {
2527
System.out.println("Enter the N value : ");
2628
int N = Integer.parseInt(scanner.nextLine().trim());
2729

28-
ArrayList<Integer> divisors = new ArrayList<>();
30+
TreeSet<Integer> divisors = new TreeSet<>();
2931
for(int i=1;i<N;i++){
3032
int d = N % i;
3133
if(d == 0){
@@ -39,7 +41,6 @@ public static void main(String[] args) {
3941
if(N/i <= i)
4042
break;
4143
}
42-
Collections.sort(divisors);
4344
System.out.println("The divisors of "+N+" are : "+divisors.toString() );
4445
System.out.println("Number of Divisors are : "+divisors.size());
4546
scanner.close();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.java.patterns;
2+
3+
import java.util.Scanner;
4+
5+
/*
6+
Write a Java Program to print the following Pattern
7+
5 5 5 5 5 5 5 5 5
8+
4 4 4 4 4 4 4
9+
3 3 3 3 3
10+
2 2 2
11+
1
12+
*/
13+
public class Pattern10 {
14+
public static void main(String[] args) {
15+
Scanner scanner = new Scanner(System.in);
16+
System.out.println("Enter the number of rows to print the pattern :: ");
17+
int N = Integer.parseInt(scanner.nextLine().trim());
18+
for(int i=N;i>=1;i--){
19+
for(int j=0;j<2*(N-i);j++)
20+
System.out.print(" ");
21+
for(int j=0;j<(2*i)-1;j++)
22+
if( j == 0)
23+
System.out.print("*");
24+
else
25+
System.out.print(" *");
26+
if(i > 1 )
27+
System.out.println();
28+
}
29+
scanner.close();
30+
}
31+
}
32+
/*
33+
OUTPUT
34+
Enter the number of rows to print the pattern :: 5
35+
5 5 5 5 5 5 5 5 5
36+
4 4 4 4 4 4 4
37+
3 3 3 3 3
38+
2 2 2
39+
1
40+
*/

0 commit comments

Comments
 (0)